Warum so kompliziert. Man kann auch Windows das ganze machen lassen:
QueueUserWorkItem.
Delphi-Quellcode:
function Thread(p: Pointer): Integer; stdcall;
var
LBIndex : Cardinal;
Cnt : Cardinal;
begin
LBIndex := PThreadParams(p)^.LBIndex;
TListbox(frmReceiver.FindComponent('Listbox' + IntToStr(LBIndex))).Items.Clear;
for cnt := 0 to 29 do
begin
TListbox(frmReceiver.FindComponent('Listbox' + IntToStr(LBIndex))).Items.Add(IntToStr(cnt));
sleep(100);
end;
result := 0;
end;
procedure TfrmReceiver.WMCOPYDATA(var msg: TWMCopyData);
var
idx : Integer;
ThreadParams : PThreadParams;
begin
idx := PMyRecord(msg.CopyDataStruct.lpData)^.idx;
New(ThreadParams);
ThreadParams.LBIndex := idx;
if QueueUserWorkItem(@Thread, ThreadParams, WT_EXECUTEDEFAULT or 2 shl 16) = 0 then
ShowMessage(SysErrorMessage(GetLastError));
end;