C
chenshu_sc
Unregistered / Unconfirmed
GUEST, unregistred user!
我的程序如下:
unit FormMain;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
th1 = class(TThread)
s : string;
FStatus : Integer;
FMemo : TMemo;
private
procedure w;
procedure showresult;
protected
procedure Execute ;
override;
public
constructor Create(Suspended:Boolean ;
Status : Integer ;
mem : TMemo);
end;
th2 = class(TThread)
s : string;
FStatus : Integer;
FMemo : TMemo;
private
procedure w;
procedure showresult;
protected
procedure Execute ;
override;
public
constructor Create(Suspended:Boolean ;
Status : Integer ;
mem : TMemo);
end;
TForm1 = class(TForm)
Memo1: TMemo;
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
i : Integer;
t1 : th1;
t2 : th2;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure th1.w;
begin
try
if FStatus = 1 then
begin
FStatus := 2;
sleep(1000);
s := 'TH1';
FStatus := 1;
end;
finally
end;
end;
procedure th1.showresult;
begin
FMemo.Lines.Add(s);
end;
procedure th1.Execute ;
begin
while not terminateddo
begin
w;
Synchronize(showresult);
end;
end;
constructor th1.Create(Suspended:Boolean ;
Status : Integer ;
mem : TMemo);
begin
inherited Create(Suspended);
FreeOnTerminate:=True;
FStatus := Status;
FMemo := mem;
end;
procedure th2.w;
begin
try
if FStatus = 1 then
begin
FStatus := 2;
sleep(300);
s := 'TH2';
FStatus := 1;
end;
finally
end;
end;
procedure th2.showresult;
begin
FMemo.Lines.Add(s);
end;
procedure th2.Execute ;
begin
while not terminateddo
begin
w;
Synchronize(showresult);
end;
end;
constructor th2.Create(Suspended:Boolean ;
Status : Integer ;
mem : TMemo);
begin
inherited create(suspended);
FreeOnTerminate:=True;
FStatus := Status;
FMemo := mem;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
i := 1;
t1 := th1.Create(false,i,memo1);
t2 := th2.Create(false,i,memo1);
end;
end.
很明显没有达到要求,但不知道该怎么改?请各位大大帮忙!
unit FormMain;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
th1 = class(TThread)
s : string;
FStatus : Integer;
FMemo : TMemo;
private
procedure w;
procedure showresult;
protected
procedure Execute ;
override;
public
constructor Create(Suspended:Boolean ;
Status : Integer ;
mem : TMemo);
end;
th2 = class(TThread)
s : string;
FStatus : Integer;
FMemo : TMemo;
private
procedure w;
procedure showresult;
protected
procedure Execute ;
override;
public
constructor Create(Suspended:Boolean ;
Status : Integer ;
mem : TMemo);
end;
TForm1 = class(TForm)
Memo1: TMemo;
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
i : Integer;
t1 : th1;
t2 : th2;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure th1.w;
begin
try
if FStatus = 1 then
begin
FStatus := 2;
sleep(1000);
s := 'TH1';
FStatus := 1;
end;
finally
end;
end;
procedure th1.showresult;
begin
FMemo.Lines.Add(s);
end;
procedure th1.Execute ;
begin
while not terminateddo
begin
w;
Synchronize(showresult);
end;
end;
constructor th1.Create(Suspended:Boolean ;
Status : Integer ;
mem : TMemo);
begin
inherited Create(Suspended);
FreeOnTerminate:=True;
FStatus := Status;
FMemo := mem;
end;
procedure th2.w;
begin
try
if FStatus = 1 then
begin
FStatus := 2;
sleep(300);
s := 'TH2';
FStatus := 1;
end;
finally
end;
end;
procedure th2.showresult;
begin
FMemo.Lines.Add(s);
end;
procedure th2.Execute ;
begin
while not terminateddo
begin
w;
Synchronize(showresult);
end;
end;
constructor th2.Create(Suspended:Boolean ;
Status : Integer ;
mem : TMemo);
begin
inherited create(suspended);
FreeOnTerminate:=True;
FStatus := Status;
FMemo := mem;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
i := 1;
t1 := th1.Create(false,i,memo1);
t2 := th2.Create(false,i,memo1);
end;
end.
很明显没有达到要求,但不知道该怎么改?请各位大大帮忙!