Author Topic: AsyncProcess not firing OnReadData event  (Read 338 times)

dugga_doo

  • Newbie
  • Posts: 2
AsyncProcess not firing OnReadData event
« on: August 13, 2026, 03:51:11 pm »
I can't AsyncProcess1 to work correctly. As far as I can tell, OnReadData never fires.

I've tried stripping it right back to basics, like this.

Code: Pascal  [Select][+][-]
  1.   TForm1 = class(TForm)
  2.     AP1: TAsyncProcess;
  3.     Button1: TButton;
  4.     Memo1: TMemo;
  5.     procedure AP1ReadData(Sender: TObject);
  6.     procedure Button1Click(Sender: TObject);
  7.   private
  8.  
  9.   public
  10.  
  11.   end;
  12.  
  13. var
  14.   Form1: TForm1;
  15.  
  16. implementation
  17.  
  18. {$R *.lfm}
  19.  
  20. { TForm1 }
  21.  
  22. procedure TForm1.Button1Click(Sender: TObject);
  23. begin
  24.   AP1.Executable := '/usr/bin/cat';
  25.   AP1.Parameters.Add('/etc/hosts');
  26.   AP1.Options := [poUsePipes, poStderrToOutPut];
  27.   AP1.Execute;
  28.   while AP1.Running do
  29.   begin
  30.     memo1.Lines.add('Running');
  31.     Sleep(200);
  32.     Application.ProcessMessages;
  33.     memo1.Lines.add('Done');
  34.   end;
  35. end;
  36.  
  37. procedure TForm1.AP1ReadData(Sender: TObject);
  38. begin
  39.   memo1.Lines.add('Read Data Here');
  40. end;

The memo1 contents:

Code: Text  [Select][+][-]
  1. Running
  2. Done

As you can see, there are no 'Read Data here' lines, so the event is not firing.

Anyone got any ideas?
Am I missing a compiler option in my Lazarus or Project Options?
Is this some weird Linux/KDE/QT thing?

Operating System: Kubuntu 24.04
KDE Plasma Version: 5.27.12
KDE Frameworks Version: 5.115.0
Qt Version: 5.15.13
Kernel Version: 6.8.0-136-generic (64-bit)
Graphics Platform: X11

Thausand

  • Hero Member
  • *****
  • Posts: 613
Re: AsyncProcess not firing OnReadData event
« Reply #1 on: August 13, 2026, 11:07:40 pm »
What is version lazarus and fpc ? (help, about lazarus)
A docile goblin always follow HERMES.md

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 12715
  • Debugger - SynEdit - and more
    • wiki
Re: AsyncProcess not firing OnReadData event
« Reply #2 on: August 13, 2026, 11:50:54 pm »
I just had a quick look.

It uses "AddPipeEventHandler" and on Qt5/QT6 this looks like

Code: Pascal  [Select][+][-]
  1. function TQtWidgetSet.AddPipeEventHandler(AHandle: TLCLHandle;
  2.   AEventHandler: TPipeEvent; AData: PtrInt): PPipeEventHandler;
  3. begin
  4.   // todo
  5.   Result := nil;
  6. end;
  7.  

"TODO" => not working.

I haven't checked the other WS....  Windows should have it (but may actually fire more often than it should, not sure / needs to be tested). Afaik GTK2 should have it, but don't know.


You can try TDebugAsyncProcess in lazdebuggers (that may also have issues of doing to much on Windows), but afaik should run on all other. It does need cthreads, as it simply starts a thread to wait for input.

Thausand

  • Hero Member
  • *****
  • Posts: 613
Re: AsyncProcess not firing OnReadData event
« Reply #3 on: August 14, 2026, 12:32:37 am »
Afaik GTK2 should have it, but don't know.
I not have look if gtk have this but example code dugga_doo is work for gtk.
A docile goblin always follow HERMES.md

dugga_doo

  • Newbie
  • Posts: 2
Re: AsyncProcess not firing OnReadData event
« Reply #4 on: August 14, 2026, 10:36:34 am »
I just had a quick look.

It uses "AddPipeEventHandler" and on Qt5/QT6 this looks like

Code: Pascal  [Select][+][-]
  1. function TQtWidgetSet.AddPipeEventHandler(AHandle: TLCLHandle;
  2.   AEventHandler: TPipeEvent; AData: PtrInt): PPipeEventHandler;
  3. begin
  4.   // todo
  5.   Result := nil;
  6. end;
  7.  

"TODO" => not working.

I haven't checked the other WS....  Windows should have it (but may actually fire more often than it should, not sure / needs to be tested). Afaik GTK2 should have it, but don't know.

It works if I compile it for GTK2. Irritating, but at least I have a workaround.
I'll report it as a bug on the Lazarus tracker. I figure it won't get fixed if no-one tells them there's a problem.
The registration process is ridiculous. Giving my credit card details, just to report a bug? No way. :o

You can try TDebugAsyncProcess in lazdebuggers (that may also have issues of doing to much on Windows), but afaik should run on all other. It does need cthreads, as it simply starts a thread to wait for input.
That sounds complicated, and way beyond my coding capabilities.  :-[
« Last Edit: August 14, 2026, 10:43:56 am by dugga_doo »

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 12715
  • Debugger - SynEdit - and more
    • wiki
Re: AsyncProcess not firing OnReadData event
« Reply #5 on: August 14, 2026, 11:05:52 am »
As far as I know you don't need a credit card to register. I certainly didn't. And I have seen someone claiming last year, and then I tested, and created myself a 2nd account, and again I did not need a credit card. I have not tested again now...

But you may have to pay attention to detail, the "personal account" option may be somewhere in grey. Also, I can only test from my location, and maybe the have country based rules.

---EDIT:

I googled, it says its a risk base decision. If your IP, your location, your email domain, your browser, ... are all on "high risk" lists then you may be asked.

I usually use Firefox, but Chrome may be the better choice. Then at least your browser may not be adding to the risk level. Same about email providers, I don't know yours, but there are a few providers that are often considered high spam risks (I am not sure, I think we have or had e.g. proton on our list for this forum once).


 

TinyPortal © 2005-2018