unit Unit1;
interface
uses
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.StdCtrls,
IdBaseComponent, IdThreadComponent;
type
TForm1 = class(TForm)
Button1: TButton;
IdThreadComponent1: TIdThreadComponent;
Label1: TLabel;
Label2: TLabel;
procedure ThreadTestRun(Sender: TIdThreadComponent);
procedure Button1Click(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
ThreadTest: TIdThreadComponent;
B: boolean;
implementation
{$R *.fmx}
procedure TForm1.Button1Click(Sender: TObject);
begin
B:= true;
ThreadTest:= TIdThreadComponent.Create(nil);
ThreadTest.OnRun:=ThreadTestRun;
ThreadTest.Start;
sleep(1000);
B:= false;
ThreadTest:= TIdThreadComponent.Create(nil);
ThreadTest.OnRun:=ThreadTestRun;
ThreadTest.Start;
end;
procedure TForm1.ThreadTestRun(Sender: TIdThreadComponent); // Hier sollte noch ein Parameter mehr sein, damit ich bei Punkt1/Punkt2 eine Variable zahl bekomme! z.B so in etwa procedure TForm1.ThreadTestRun(Sender: TIdThreadComponent; X: Integer)
var
I: Integer;
begin
if B then begin
for I := 0 to 40 do begin // (Punkt 1) for I := 0 to X do begin
label1.Text := 'Thread Nr.1 = ' +I.ToString();
sleep(400);
end;
end
else begin
for I := 0 to 30 do begin // (Punkt 2) for I := 0 to X do begin
label2.Text := 'Thread Nr.2 = ' +I.ToString();
sleep(400);
end;
end;
ThreadTest.Destroy; // Versuch den Thread zu beenden!
ThreadTest.Free;
end;
end.