{ Important: Methods and properties of objects in VCL can only be used in a
method called using Synchronize, for example,
Synchronize(UpdateCaption);
and UpdateCaption could look like,
procedure PMessage.UpdateCaption;
begin
Form1.Caption := 'Updated in a thread';
end; }
{ PMessage }
uses Main;
procedure MsgThread.Execute;
var Msg : TMsg;
begin
{ Place thread code here }
FMyString := 'Thread Start!';
Synchronize(ShowString);
while (not Terminated) do
begin
if PeekMessage(Msg,0,0,0,PM_REMOVE) then
begin
if (Msg.message = WM_QUIT) then
begin
FMyString := 'Thread Quit';
Synchronize(ShowString);
Terminate;
end;
if (Msg.message = WM_MyMessage) then
begin
FMyString := 'Thread Get a USER Message!';
Synchronize(ShowString);
end;
end;
end;
end;
procedure MsgThread.ShowString;
begin
Form1.ListBox1.Items.Add(FMyString);
end;