Leider funktioniert es nicht.
Habe mal folgenden Versuch gemacht:
Delphi-Quellcode:
type
TForm1 = class(TForm)
Memo1: TMemo;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
FMyThread: TMyThread;
procedure progress(value: Integer);
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
Memo1.Clear;
FMyThread := TMyThread.Create(true);
FMyThread.Progress := progress;
FMyThread.Resume;
end;
procedure TForm1.progress(value: Integer);
begin
Memo1.Lines.Add('Value: ' + IntToStr(value));
sleep(500);
end;
Delphi-Quellcode:
type
TProgress = procedure(Value: integer) of object;
type
TMyThread = class(TThread)
private
FValue: Integer;
FProgress: TProgress;
procedure SyncProgress;
protected
procedure Execute; override;
public
property Progress: TProgress write FProgress;
end;
implementation
uses
Windows, SysUtils;
{ TMyThread }
procedure TMyThread.Execute;
var
i: Integer;
begin
for i := 1 to 10 do
begin
FValue := i;
Queue(SyncProgress);
sleep(200);
OutputDebugString(PWideChar('FValue: ' + IntToStr(FValue)));
end;
end;
procedure TMyThread.SyncProgress;
begin
FProgress(FValue);
end;
Die Ausgabe sieht so aus:
Zitat:
Value: 1
Value: 3
Value: 5
Value: 8
Value: 10
Value: 10
Value: 10
Value: 10
Value: 10
Value: 10