unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, jpeg, ExtCtrls;
const
PM_App = WM_APP + 1;
type
TForm1 =
class(TForm)
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
procedure PMApp(
var Msg: TMessage);
message PM_App;
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
type
TMyThread =
record
ThreadID: DWORD;
ThreadHandle: THandle;
OutPut :TLabel;
MyID :Integer;
Count :Integer;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
var
MyThread :
Array[0..10]
of TMyThread;
olabel :
Array[0..2]
of TLabel;
// = (Form1.Label1,Form1.Label2,Form1.Label3);
{******************************************************************************
TForm1.PMApp(var Msg: TMessage) - 12/23/2009 12:25
By: DiKo
******************************************************************************}
procedure TForm1.PMApp(
var Msg: TMessage);
var
i :Integer;
begin
i := Integer(Msg.lParam);
MyThread[i].OutPut.Caption:='
Ich bin T#'+IntToStr(MyThread[i].MyID)+'
'+IntToStr(MyThread[i].Count);
end;
{TForm1.PMApp(var Msg: TMessage)}
{******************************************************************************
Flashing(zahl: Pointer): LongInt; stdcall - 12/22/2009 4:13
******************************************************************************}
function Flashing(varptr: Pointer): LongInt;
stdcall;
var
i,n :Integer;
begin
n:=integer(varptr^);
for i:=0
to 70
do begin
MyThread[n].Count:=i;
PostMessage(Form1.Handle, PM_App, 0, MyThread[n].MyID);
sleep(700+(n*200));
end;
Result:=0;
end;
{Flashing(zahl: Pointer): LongInt; stdcall}
procedure TForm1.Button1Click(Sender: TObject);
var
i :Integer;
begin
olabel[0]:=Label1;
olabel[1]:=Label2;
olabel[2]:=Label3;
for i:=0
to 2
do begin
MyThread[i].MyID:=i;
MyThread[i].OutPut:=oLabel[i];
MyThread[i].ThreadHandle:=CreateThread(
nil, 0, TFNThreadStartRoutine(@Flashing),@MyThread[i].MyID, 0, MyThread[i].ThreadID);
if MyThread[i].ThreadHandle<>0
then CloseHandle(MyThread[i].ThreadHandle);
end;
end;
end.