Recent

Author Topic: TProcess output to a TMemo  (Read 3166 times)

Dzandaa

  • New Member
  • *
  • Posts: 22
TProcess output to a TMemo
« on: August 04, 2021, 08:33:23 pm »
Hi,

Is it possible to write the output (String) of a TProcess in a TMemo Line by Line?

Thank you.


winni

  • Hero Member
  • *****
  • Posts: 2806
Re: TProcess output to a TMemo
« Reply #1 on: August 04, 2021, 09:26:33 pm »
Hi!

I don't understand the reason of this question, but:

You can assign your output string to a temporay stringlist and add the lines one by one:

Code: Pascal  [Select][+][-]
  1. ...
  2. tmpStringList := TStringList.create;
  3. tmpStringList.text := OutputString;
  4. for i := 0 to tmpStringList.count - 1 do
  5.     memo1.lines.add (tmpStringList[i]);
  6. tmpStringList.free;
  7. ...

Winni

Edson

  • Hero Member
  • *****
  • Posts: 1223
Re: TProcess output to a TMemo
« Reply #2 on: August 04, 2021, 10:01:06 pm »
I would recommend https://github.com/t-edson/UnTerminal

It's a wrapper for a wrapper for TProcess with prompt detection and event driven.
Lazarus 2.0.10 - FPC 3.2.0 - x86_64-win64 on Windows 8

Jurassic Pork

  • Hero Member
  • *****
  • Posts: 1063
Re: TProcess output to a TMemo
« Reply #3 on: August 05, 2021, 12:42:00 am »
hello,
Is it possible to write the output (String) of a TProcess in a TMemo Line by Line?.
what do you mean for that ? send the stdout and stderr of the process in real  time to the tmemo while process is running ?

with UnTerminal  you can do that -> see attachment  ( Example 2 of UnTerminal)

Edson -> I have modified your example because On Windows Strings must be converted from OEM to UTF8  (for latin characters ex : é )
Code: Pascal  [Select][+][-]
  1. uses LazUTF8;
  2. // ....
  3.  
  4. procedure TForm1.procLineCompleted(const lin: string);
  5. begin
  6.   if LinPartial then begin
  7.     //Estamos en la línea del prompt
  8.     Memo1.Lines[Memo1.Lines.Count-1] := ConsoleToUTF8(lin);  //reemplaza última línea
  9.     LinPartial := false;
  10.   end else begin  //caso común
  11.     Memo1.Lines.Add(ConsoleToUTF8(lin));
  12.   end;
  13. end;
  14.  
  15. procedure TForm1.procReadData(nDat: integer; const lastLin: string);
  16. begin
  17.   LinPartial := true;   //marca bandera
  18.   Memo1.Lines.Add(ConsoleToUTF8(lastLin));   //agrega la línea que contiene al prompt
  19. end;              

Friendly, J.P
Jurassic computer : Sinclair ZX81 - Zilog Z80A à 3,25 MHz - RAM 1 Ko - ROM 8 Ko

Dzandaa

  • New Member
  • *
  • Posts: 22
Re: TProcess output to a TMemo
« Reply #4 on: August 05, 2021, 02:16:38 pm »
Thank you very much.

I've try it and it work :)

in linux C++ using cout, just have to add cout.flush() after each output.


Edson

  • Hero Member
  • *****
  • Posts: 1223
Re: TProcess output to a TMemo
« Reply #5 on: August 05, 2021, 08:31:28 pm »
Edson -> I have modified your example because On Windows Strings must be converted from OEM to UTF8  (for latin characters ex : é )

Not problem. It's a good contribution.

I realize I need to complete some translations to English  :-\.
Lazarus 2.0.10 - FPC 3.2.0 - x86_64-win64 on Windows 8

 

TinyPortal © 2005-2018