下面是具体的代码,第一次按button可以showmessage,在按就没有用了,不知道是什么原因,代码很简单,请各位大哥不要嫌麻烦,一定看一看,谢了~~~~ procedure TForm1.Button1Click(Sender: TObject); begin a1.Resume; end;
procedure TForm1.FormCreate(Sender: TObject); begin a1:=a.Create(true); end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction); begin a1.Free; end; ///下面是线程中的代码 procedure a.Execute; var i:byte; begin FreeOnTerminate:=false; for i:=1 to 200 do begin form1.Edit1.Text:=inttostr(i); end; showmessage('yes'); suspend; end;
----------------------------------------------
-
type a = class(TThread) private { Private declarations } protected procedure Execute; override; end;
implementation uses unit1; { a }
procedure a.Execute; var i:byte; begin FreeOnTerminate:=false; for i:=1 to 200 do begin form1.Edit1.Text:=inttostr(i); end; showmessage('yes'); suspend; end;
这样吧 type tmythread=class(TThread) private public procedure Execute;override; constructor create(ad:boolean); destructor destroy; end ; var Form1: TForm1; a1:tmythread; implementation
{$R *.dfm} constructor tmythread.create(ad:boolean); begin inherited create(ad); end;
destructor tmythread.destroy; begin inherited; end; procedure tmythread.Execute; var i:byte; begin for i:=1 to 200 do begin form1.Edit1.Text:=inttostr(i); form1.Edit1.Update ; end; end;
procedure TForm1.myter(Sender: TObject); begin showmessage('yes'); end;
procedure TForm1.Button1Click(Sender: TObject); begin a1:=tmythread.Create(true); a1.FreeOnTerminate :=false; a1.OnTerminate :=myter; a1.Resume;
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction); begin a1.Free ; end;