Danke Uwe, ich hoffe ich habe es richtig verstanden:
Delphi-Quellcode:
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TProgress =
procedure(
const Value: integer)
of object;
type
TMyThread =
class(TThread)
private
FValue: Integer;
FProgress: TProgress;
procedure SyncProgress(Value:Integer);
protected
procedure Execute;
override;
public
property Progress: TProgress
write FProgress;
end;
TForm2 =
class(TForm)
Memo1: TMemo;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private-Deklarationen }
FMyThread: TMyThread;
procedure progress(
const value: Integer);
public
{ Public-Deklarationen }
end;
var
Form2: TForm2;
implementation
{$R *.dfm}
procedure TMyThread.Execute;
var
i: Integer;
begin
for i := 1
to 10
do
begin
FValue := i;
SyncProgress(i);
sleep(200);
OutputDebugString(PWideChar('
FValue: ' + IntToStr(FValue)));
end;
end;
procedure TMyThread.SyncProgress(Value:Integer);
begin
Queue(
Procedure
begin
FProgress(Value);
end
);
end;
procedure TForm2.Button1Click(Sender: TObject);
begin
Memo1.Clear;
FMyThread := TMyThread.Create(true);
FMyThread.Progress := progress;
FMyThread.Resume;
end;
procedure TForm2.progress(
const value: Integer);
begin
Memo1.Lines.Add('
Value: ' + IntToStr(value));
sleep(500);
end;
end.
Korrekturvorschläge willkommen....