令
令狐小侠
Unregistered / Unconfirmed
GUEST, unregistred user!
unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;type TForm1 = class(TForm) Memo1: TMemo;
Button1: TButton;
Button2: TButton;
procedure FormShow(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private { Private declarations } public { Public declarations } end;
TAdd1= class(Tthread) fstringlist : Tstringlist;
protected procedure Execute;override;
procedure Assign;
public Constructor Create;
end;
Tadd2 = class(Tthread) i : int64;
protected procedure Execute;override;
public end;
var Form1: TForm1;
add1 : Tadd1;
add2 : Tadd2;implementation{$R *.dfm}{ TAdd1 }procedure TAdd1.Assign;
begin
form1.Memo1.Lines.add(fstringlist[0]);
end;
constructor TAdd1.Create;
begin
inherited create(true);
fstringlist := Tstringlist.Create;
end;
procedure TAdd1.Execute;
begin
while not self.Terminateddo
begin
if Fstringlist.Count>0 then
begin
self.Synchronize(assign);
fstringlist.Delete(0);
end else
sleep(10);
end;
end;
{ Tadd2 }procedure Tadd2.Execute;var stri : string;
begin
i :=0;
while not self.Terminateddo
begin
inc(i);
stri:= inttostr(i);
add1.fstringlist.Add(stri);
sleep(1);
end;
end;
procedure TForm1.FormShow(Sender: TObject);
begin
Add1 := Tadd1.Create;
add2 := TAdd2.Create(true);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Add1.Resume;
add2.Resume;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
add1.Suspend;
add2.Suspend;
end;
end.
//大家运行一下就知道 怎么回事了
Button1: TButton;
Button2: TButton;
procedure FormShow(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private { Private declarations } public { Public declarations } end;
TAdd1= class(Tthread) fstringlist : Tstringlist;
protected procedure Execute;override;
procedure Assign;
public Constructor Create;
end;
Tadd2 = class(Tthread) i : int64;
protected procedure Execute;override;
public end;
var Form1: TForm1;
add1 : Tadd1;
add2 : Tadd2;implementation{$R *.dfm}{ TAdd1 }procedure TAdd1.Assign;
begin
form1.Memo1.Lines.add(fstringlist[0]);
end;
constructor TAdd1.Create;
begin
inherited create(true);
fstringlist := Tstringlist.Create;
end;
procedure TAdd1.Execute;
begin
while not self.Terminateddo
begin
if Fstringlist.Count>0 then
begin
self.Synchronize(assign);
fstringlist.Delete(0);
end else
sleep(10);
end;
end;
{ Tadd2 }procedure Tadd2.Execute;var stri : string;
begin
i :=0;
while not self.Terminateddo
begin
inc(i);
stri:= inttostr(i);
add1.fstringlist.Add(stri);
sleep(1);
end;
end;
procedure TForm1.FormShow(Sender: TObject);
begin
Add1 := Tadd1.Create;
add2 := TAdd2.Create(true);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Add1.Resume;
add2.Resume;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
add1.Suspend;
add2.Suspend;
end;
end.
//大家运行一下就知道 怎么回事了