unit Unit1;
interface
uses
Winapi.Windows,
Winapi.Messages, System.SysUtils, System.Variants, System.Classes,
Vcl.Graphics,
Vcl.Controls,
Vcl.Forms,
Vcl.Dialogs, Generics.Collections,
Vcl.StdCtrls;
type
TSammelListe =
Class(TList<TGraphicControl>);
TAnalyseThread =
class(TThread)
private
FList : TSammelListe;
protected
procedure Execute;
override;
public
Status : AnsiString;
OnReady : TNotifyEvent;
constructor Create(CreateSuspended : Boolean);
destructor Destroy;
override;
end;
type
TForm1 =
class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private-Deklarationen }
AnalyseThread : TAnalyseThread;
procedure OnAnalyseReady(Sender: TObject);
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
if Assigned(AnalyseThread)
then
begin
AnalyseThread.Terminate;
FreeAndNil(AnalyseThread);
end;
AnalyseThread := TAnalyseThread.Create(True);
if Assigned(AnalyseThread)
then
begin
AnalyseThread.OnReady := OnAnalyseReady;
AnalyseThread.Start;
end;
end;
procedure TForm1.OnAnalyseReady(Sender: TObject);
begin
//Auswertung des Daten...
if Assigned(AnalyseThread)
then
begin
AnalyseThread.Terminate;
FreeAndNil(AnalyseThread);
end;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
if Assigned(AnalyseThread)
then
begin
AnalyseThread.Terminate;
FreeAndNil(AnalyseThread);
end;
end;
{ TAnalyseThread }
constructor TAnalyseThread.Create(CreateSuspended: Boolean);
begin
inherited Create(CreateSuspended);
FList := TSammelListe.Create;
FreeOnTerminate := False;
end;
destructor TAnalyseThread.Destroy;
begin
if Assigned(FList)
then
begin
FList.Clear;
FreeAndNil(FList);
end;
inherited Destroy;
end;
procedure TAnalyseThread.Execute;
begin
inherited;
//Tue irgendwas bis fertig...
if Assigned(OnReady)
then
OnReady(Self);
end;
end.