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.