unit MyThread;
interface
uses
Windows,Classes,SysUtils,ComCtrls)
TMyThread = class(TThread)
private
AHandle : THandle;
protected
procedure Execute;override;
public
published
protected
public
constructor Create(
Handle:THandle);virtual;
destructor Destroy;override;
published
end;
implementation
{Type-TDriveThread-Anfang******************************************************}
{Protected-TDriveThread-Anfang*************************************************}
procedure TMyThread.Execute;
var
I : intger;
begin
inherited;
I := 0;
SendMessage(AHandle,WM_USER+10,0,0); // Für Senden für Meldungen
while GetAsyncKeystate(VK_ESCAPE) <> 0 do//abbruch wenn ESC-Taste
begin
SendMessage(AHandle,WM_USER+11,0,I); //
inc(I);
end;
SendMessage(AHandle,WM_USER+12,0,0);
end;
{Protected-TDriveThread-Ende***************************************************}
{Public-TDriveThread-Anfang****************************************************}
constructor TMyThread.Create(
Handle:THandle);
begin
inherited Create(true);
AHandle :=
Handle;
Priority := tpLowest;//Die Eigenschaft Priority gibt die Priorität des Thread an.
// Je nach Bedarf kann eine höhere oder niedrigere Priorität zugeordnet werden.
end;
//------------------------------------------------------------------------------
destructor TMyThread.Destroy;
begin
inherited;
end;
{Public-TDriveThread-Ende******************************************************}
{Type-TDriveThread-Ende********************************************************}
uses
MyThread;
{in Haupform}
private
FMyThread : TMyThread;
procedure WM_USER10(var Msg: TMessage); message WM_USER+10;
procedure WM_USER11(var Msg: TMessage); message WM_USER+11;
procedure WM_USER12(var Msg: TMessage); message WM_USER+12;
procedure TMain.FormDestroy(Sender: TObject);
begin
FreeAndNil(FProgressbarThread);
end;
procedure TMain.Button1Click(Sender: TObject);
begin
FMyThread := TMyThread.Create(
Handle);
FMyThread.Resume;
end;
procedure TMain.WM_USER10(var Msg: TMessage);
begin
Label1.Caption := 'Start';
end;
procedure TMain.WM_USER11(var Msg: TMessage);
begin
Label2.Caption := intToStr(Msg.LParam);
end;
procedure TMain.WM_USER11(var Msg: TMessage);
begin
Label3.Caption := 'Fertig';
end;