const
WM_ADDMESSAGE = WM_USER + 1;
type
TForm1 =
class(TForm)
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private-Deklarationen }
_CS: TRTLCriticalSection;
_SL: TStrings;
procedure WMAddMessage(
var Message: TMsg);
message WM_ADDMESSAGE;
public
{ Public-Deklarationen }
procedure AddLog(
const S:
String);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
InitializeCriticalSection(_CS);
_SL := TStringList.Create;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
_SL.Free;
DeleteCriticalSection(_CS);
end;
procedure TForm1.WMAddMessage(
var Message: TMsg);
begin
EnterCriticalSection(_CS);
try
Log.SelAttributes.Color := clBlack;
Log.SelStart := Log.GetTextLen;
Log.SelText := _SL.Text;
_SL.Clear;
finally
LeaveCriticalSection(_CS);
end;
end;
procedure TForm1.AddLog(
const S:
String);
begin
EnterCriticalSection(_CS);
try
_SL.Add('
[' + TimeToStr(Time) + '
] ' + s);
finally
LeaveCriticalSection(_CS);
end;
PostMessage(
Handle, WM_ADDMESSAGE, 0, 0);
end;