Hello, I found the code on the Internet and I have a problem with the output of data from the console.
On the screenshot, the first component of the TreeView1 output is not correct, the second Memo1 output is correct.
I have such a question, why are all components except Memo1 displaying incorrectly?
const
BUF_SIZE = 4096;
// Размер буфера для чтения выходных данных, можно читать блоками по 64k
var
Form1: TForm1;
AProcess: TProcess;
ru: boolean;
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.ToggleBox1Change(Sender: TObject);
var
Buffer: string = '';
BytesRead: longint = 0;
begin
//Запуск процесса (выполнение команды dir/ls)
ru := False;
Button1.Enabled := True;
ToggleBox1.Enabled := False;
AProcess := TProcess.Create(nil);
AProcess.ShowWindow := swohide;
AProcess.Executable := 'cmd';
AProcess.Parameters.Clear;
AProcess.Parameters.Add('/c');
AProcess.Parameters.Add(
'cd compil\System\ & del Core.u del Engine.u & del Nwindow.u & del Interface.u &echo N|ucc make -NoBind');
AProcess.Options := [poUsePipes];
AProcess.Execute;
//можно дать чуть-чуть времени на отправку данных через AProcess.Output
sleep(500);
repeat
Memo1.Lines.BeginUpdate;
TreeView1.Items.BeginUpdate;
try
SetLength(Buffer, BUF_SIZE);
BytesRead := AProcess.Output.Read(Buffer[1], Length(Buffer));
if BytesRead > 0 then
begin
SetLength(Buffer, BytesRead);
Memo1.Append(Trim(Buffer));
TreeView1.Items.AddChild(nil,Trim(Buffer));
end;
finally
Memo1.Lines.EndUpdate;
TreeView1.Items.EndUpdate;
Memo1.SelStart := UTF8Length(Memo1.Text);
end;
// Sleep(50);
Application.ProcessMessages;
if BytesRead = 0 then
begin
ru := True;
BytesRead := 0;
Buffer := '';
end;
until ru = True;
end;