Jump to content

uefi

Members
  • Content Count

    29
  • Joined

  • Last visited

Community Reputation

0 Neutral

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. Hello, I can't use PYTHON4DELPHI in threads, errors keep popping up: unit Unit1; interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, pythonengine, System.syncobjs; type TForm1 = class(TForm) Button1: TButton; Memo1: TMemo; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.Button1Click(Sender: TObject); var cs:TcriticalSection; threads:integer; begin cs:=TcriticalSection.Create; for threads :=0 to 5 do TPythonThread.CreateAnonymousThread( procedure var val:string; Writer:TStreamWriter; PythonEngine1:TPythonEngine; begin cs.Enter; val:=''; cs.Leave; PythonEngine1:=TPythonEngine.Create(nil); PythonEngine1.LoadDll; PythonEngine1.ExecString('fun=("Hello World")'); val:=( 'Value = ' + PythonEngine1.EvalStringAsStr('fun') ); FreeAndNil(PythonEngine1); form1.Memo1.Lines.Add(val); TPythonThread.Synchronize(nil, procedure begin Writer := TStreamWriter.Create(Extractfilepath(paramstr(0))+'TEST'+'.txt', true, TEncoding.Ansi); Writer.WriteLine(val); Writer.Free; end); end).Start; end; end.
  2. uefi

    I get value=none

    Hello, I can not get the result of the script execution instead of the result I get: value=none uses ...PythonEngine, Vcl.PythonGUIInputOutput; function pyscript:string; var PythonEngine1:TPythonEngine; PythonDelphiVar1:TPythonDelphiVar; begin PythonEngine1:=TPythonEngine.Create(nil); PythonDelphiVar1:=TPythonDelphiVar.Create(nil); PythonDelphiVar1.Engine:=PythonEngine1; //PythonEngine1.DLLName := 'python310.dll'; PythonEngine1.LoadDll; PythonEngine1.ExecString('print("Hello World")'); Result:=( 'Value = ' + PythonDelphiVar1.ValueAsString ); FreeAndNil(PythonEngine1); FreeAndNil(PythonDelphiVar1); end; procedure TForm1.Button1Click(Sender: TObject); begin memo2.Lines.Add(pyscript); end;
×