Hi!
Natürlich brauchst Du das nicht bei jedem Schleifendurchlauf ein Syncornize zu machen, aber Du kannst auch einfach an Dein Formular ne Message senden.
Mavarik
Delphi-Quellcode:
CONST
WM_Sync = WM_User + 100;
SM_MSG = 1; // Ganzen Text
SM_Prozent = 2; // Nur %
type
PSyncMSG = ^TSyncMSG;
TSyncMSG = record
MSG : String[255];
PZ : Integer;
end;
TMaifForm = Class(TForm)
private
procedure MySyncronize(var MSG: TMessage); message WM_Sync;
end;
procedure TMyThread.Execute;
Var
MyMessage : PSyncMSG;
I : Integer;
begin
// ...
New(MyMessage);
MyMessage^.MSG := 'Hey ich bearbeite gerade: "Cool.pdf"';
MyMessage^.PZ := 7;
Postmessage(MainForm.Handle,WM_Sync,SM_MSG,LParam(MyMessage));
for i:=0 to 100 do
begin
if I mod 10 = 0 then
begin
New(MyMessage);
MyMessage^.MSG := '';
MyMessage^.PZ := i;
Postmessage(MainForm.Handle,WM_Sync,SM_Prozent,LParam(MyMessage));
end;
end;
// ...
end;
procedure TMainform.MySyncronize(var MSG: TMessage);
var
SyncMSG : PSyncMSG;
begin
SyncMSG := PSyncMSG(MSG.LParam);
Case MSG.WParam of
SM_MSG : begin
Label1.Caption := SyncMSG^.MSG;
Processbar1.Position := SyncMSG^.PZ;
end;
SM_Prozent : begin
Processbar1.Position := SyncMSG^.PZ;
end;
end;
Dispose(SyncMSG);
end;