//==========================mythread.pas=================//
unit mythread;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ComCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
p1: TProgressBar;
p2: TProgressBar;
Button2: TButton;
Button3: TButton;
Button4: TButton;
Button5: TButton;
Button6: TButton;
Button7: TButton;
Edit1: TEdit;
Edit2: TEdit;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure Button5Click(Sender: TObject);
procedure Button6Click(Sender: TObject);
procedure Button7Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
T1 = class( TThread)
public
constructor create( thebar: Tprogressbar);
protected
procedure execute;
override;
private
fbar: Tprogressbar;
end;
T2 = class( TThread)
public
constructor create( theedit: TEdit);
protected
procedure execute;
override;
private
fedit: Tedit;
proceduredo
loop;
end;
var
Form1: TForm1;
Ta,Tb: T1;
//ta, Tb: T2;
implementation
{$R *.DFM}
constructor T1.create( thebar: Tprogressbar);
begin
inherited create( true);
fbar:= thebar;
end;
Procedure T1.execute;
begin
repeat
synchronize( fbar.StepIt);
if fbar.Position>= fbar.Max then
fbar.position:=fbar.min;
until terminated;
end;
constructor T2.create( theedit: TEdit);
begin
inherited create( true);
fedit:= theedit;
fedit.Text:='0';
end;
Procedure T2.execute;
begin
repeat
synchronize(do
loop);
if strtoint(fedit.Text)>=10000 then
fedit.Text:= '0';
until terminated;
end;
procedure T2.doloop;
begin
fedit.Text:=inttostr( strtoint( fedit.text)+1);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
ta.Resume;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
ta.Suspend;
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
ta.Terminate;
end;
procedure TForm1.Button4Click(Sender: TObject);
begin
tb.Resume;
end;
procedure TForm1.Button5Click(Sender: TObject);
begin
tb.Suspend;
end;
procedure TForm1.Button6Click(Sender: TObject);
begin
tb.Terminate;
end;
procedure TForm1.Button7Click(Sender: TObject);
begin
ta:=t1.create( p1);
tb:=t1.create( p2);
end;
end.
//======================end of mythread.pas==================//
//======================mythread.dfm=========================//
object Form1: TForm1
Left = 192
Top = 107
Width = 544
Height = 375
Caption = 'Form1'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
object Button1: TButton
Left = 272
Top = 64
Width = 75
Height = 25
Caption = 'resume'
TabOrder = 0
OnClick = Button1Click
end
object p1: TProgressBar
Left = 96
Top = 64
Width = 150
Height = 16
Min = 0
Max = 1000
TabOrder = 1
end
object p2: TProgressBar
Left = 96
Top = 112
Width = 150
Height = 16
Min = 0
Max = 1000
TabOrder = 2
end
object Button2: TButton
Left = 352
Top = 64
Width = 75
Height = 25
Caption = 'suspend'
TabOrder = 3
OnClick = Button2Click
end
object Button3: TButton
Left = 440
Top = 64
Width = 75
Height = 25
Caption = 'teminate'
TabOrder = 4
OnClick = Button3Click
end
object Button4: TButton
Left = 272
Top = 104
Width = 75
Height = 25
Caption = 'resume'
TabOrder = 5
OnClick = Button4Click
end
object Button5: TButton
Left = 352
Top = 104
Width = 75
Height = 25
Caption = 'suspend'
TabOrder = 6
OnClick = Button5Click
end
object Button6: TButton
Left = 440
Top = 104
Width = 75
Height = 25
Caption = 'teminate'
TabOrder = 7
OnClick = Button6Click
end
object Button7: TButton
Left = 368
Top = 24
Width = 75
Height = 25
Caption = 'Button7'
TabOrder = 8
OnClick = Button7Click
end
object Edit1: TEdit
Left = 96
Top = 144
Width = 121
Height = 21
TabOrder = 9
Text = '0'
end
object Edit2: TEdit
Left = 96
Top = 184
Width = 121
Height = 21
TabOrder = 10
Text = '0'
end
end
//=======================end of mythread.dfm======================//