Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OnSendUniData event does not work #463

Open
Uefi1 opened this issue Mar 14, 2024 · 6 comments
Open

OnSendUniData event does not work #463

Uefi1 opened this issue Mar 14, 2024 · 6 comments

Comments

@Uefi1
Copy link

Uefi1 commented Mar 14, 2024

Hello, the OnSendUniData event assigned to TPythonGUIInputOutput is not WORK.

type
TRcv = class
procedure PythonInputOutputSendUniData(Sender: TObject; const Data: string);
end;

var
PythonEngine: TPythonEngine;
PythonInputOutput:TPythonGUIInputOutput;
Rcv:TRcv;
Temp:string;

{ TRcv }

procedure TRcv.PythonInputOutputSendUniData(Sender: TObject; const Data: string);
begin
Temp:='Event triggered'; //
end;

function execpythonscript(const Filename:string):string;
begin
 Result:='';
  PythonEngine := TPythonEngine.Create(nil);
    PythonInputOutput:=TPythonGUIInputOutput.Create(nil);
    PythonInputOutput.OnSendUniData:=Rcv.PythonInputOutputSendUniData;
    PythonInputOutput.UnicodeIO:=True;
    PythonInputOutput.DelayWrites:=True;
    PythonEngine.IO:=PythonInputOutput;
    PythonEngine.InitThreads := True;
    PythonEngine.UseLastKnownVersion := True
    PythonEngine.AutoLoad := False;
    PythonEngine.AutoUnload := False;
    PythonEngine.AutoFinalize := True;
    PythonEngine.RedirectIO := True;
    PythonEngine.LoadDll;
    TPythonThread.Py_Begin_Allow_Threads;
FGILState := PythonEngine.PyGILState_Ensure;
try
PythonEngine.ExecFile(Filename);
except
end;
PythonEngine.PyGILState_Release(FGILState);
Result:=Temp; //Always empty
end;
@Uefi1
Copy link
Author

Uefi1 commented Mar 14, 2024

I actually understood something: the console application does not intercept WM_USER and other messages that's why the event doesn't fire !!!!!

@Uefi1
Copy link
Author

Uefi1 commented Mar 14, 2024

I came to this conclusion after looking at how Vcl.PythonGUIInputOutput is implemented; in general, this entire Python4Delphi library is terribly and incomprehensibly written

@Uefi1
Copy link
Author

Uefi1 commented Mar 15, 2024

No, it turned out that this is not even the case: the console application does not accept messages; everything has been transferred to the form; the display also does not work! Generally a bug !

@Uefi1
Copy link
Author

Uefi1 commented Mar 15, 2024

Doesn't work in any way and under no circumstances:

procedure TForm2.PythonInputOutputSendUniData(Sender: TObject;
  const Data: string);
begin
//PythonInputOutput.DisplayString(Data);
cs.Enter;
Memo1.Lines.Add('WORK'); //NOT (
cs.Leave;
end;

procedure TForm2.InitPython;
begin
  PythonEngine := TPythonEngine.Create(nil);
  try
    PythonInputOutput:=TPythonGUIInputOutput.Create(nil);
    PythonInputOutput.OnSendUniData:=PythonInputOutputSendUniData;
    PythonEngine.IO:=PythonInputOutput;
    PythonInputOutput.UnicodeIO:=True;
    PythonInputOutput.RawOutput := False;
    PythonInputOutput.DelayWrites:=True;
    PythonEngine.InitThreads := True;
    PythonEngine.UseLastKnownVersion := False;
    PythonEngine.DllPath := ExtractFilePath(ParamStr(0));
    PythonEngine.DllName := 'python310.dll';
    PythonEngine.AutoLoad := False;
    PythonEngine.AutoUnload := False;
    PythonEngine.AutoFinalize := True;
    PythonEngine.RedirectIO := True;
    PythonEngine.LoadDll;
    TPythonThread.Py_Begin_Allow_Threads;
  finally
//
  end;
end;

@wbzhangyuan
Copy link

I also encountered this problem. Have you solved this problem? Can you tell me the solution?

@Uefi1
Copy link
Author

Uefi1 commented Dec 7, 2024

I also encountered this problem. Have you solved this problem? Can you tell me the solution?

Hello yes i read this theme forum https://en.delphipraxis.net/topic/11973-io-doesnt-work/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants