I'm sending a log message to the main form using this:
For send the message:
procedure LogMsg(Msg: string; Kind:TMsgType=msgNormal);
var
p: pChar;
begin
case Kind of
msgError: Msg := '[Error] ' + Msg;
msgInformation: Msg := '# ' + Msg;
msgExternal: Msg := 'Plugin: ' + Msg;
end;//if
GetMem(p, (Length(Msg) + 1)*SizeOf(Char));
Move(Msg[1], p^, (Length(Msg)+ 1)*SizeOf(Char));
PostMessage(Application.MainForm.Handle, WM_LOG_MESSAGE, 0, integer(p));
end;
And display it:
procedure TfrmMain.WMLog(var Message: TMessage);
var
p: pChar;
Lista:TStringList;
begin
try
p := pChar(Message.LParam);
if EditLog.Lines.Count>100 then
begin
EditLog.Lines.Clear;
end;//if
Lista := TStringList.Create;
try
Lista.Delimiter := #10;
Lista.text := p;
EditLog.Lines.AddStrings(Lista);
finally
Lista.Free;
end;//try
{$ifndef FPC}
EditLog.GotoLineAndCenter( EditLog.Lines.Count );
{$endif}
Freemem(p);
except
on E: Exception do
EditLog.Lines.Add(E.Classname + ': ' + E.Message);
end;//try
end;
This is for log the output from execute some python scripts.
However look like if the message string is too large, the process hang and is necesary kill the python process.
I was not aware that could exist a limit. PostMessage have a limit in the size of the data or could be something else?
This is with Delphi 2010.
EDIT: Sorry, I forget to show the type of msg. Is a String
.