Thread example
Delphi Source
Joao Paulo Schwarz Schuler
unit UThread1;
{ Thread example }
{ Joao Paulo Schwarz Schuler }
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type T1 = class(TThread)
private
I:integer;
procedure Mostra;
protected
procedure Execute; override;
end; { of class declaration }
type T2 = class(TThread)
private
I:integer;
procedure Execute; override;
procedure Mostra;
end; { of class declaration }
type TForm1 = class(TForm)
Label1: TLabel;
Label2: TLabel;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end; { of class declaration }
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure T1.Mostra;
begin
Form1.Label1.Caption:=IntToStr(I);
end;
procedure T1.Execute;
var LI:integer;
begin
for LI:=1 to 3000 do
begin
I:=LI;
Synchronize(Mostra);
end;
end; { of procedure }
procedure T2.Mostra;
begin
Form1.Label2.Caption:=IntToStr(I);
end;
procedure T2.Execute;
var LI:integer;
begin
for LI:=1 to 6000 do
begin
I:=LI;
Synchronize(Mostra);
end;
end; { of procedure }
procedure TForm1.Button1Click(Sender: TObject);
begin
T1.Create(false);
T2.Create(false);
end; { of procedure }
end. { of Unit }
Return to the Home Page
Return to the Fontes em Delphi 2.0