S
silaszhe
Unregistered / Unconfirmed
GUEST, unregistred user!
我继承了TThread类,构造了create。重载了execute。
在execute中写上我的函数。
请问我execute中函数的参数要怎么传递?全局变量?
比如:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
procedure test(s:string);
{ Private declarations }
public
{ Public declarations }
end;
type
TMyThread=class(TThread)
protected
procedure Execute;
override;
public
constructor create;
end;
var
Form1: TForm1;
ttest: TMyThread;
implementation
{$R *.dfm}
constructor TMyThread.create;
begin
inherited create(false);
freeonterminate:=true;//线程终止时自动删除对象
end;
procedure TMyThread.Execute;
begin
//test();
不知道这样写行不行。如果可以test的参数应该怎么传递。
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
ttest:=TMyThread.create;
end;
procedure TForm1.test(s: string);
begin
Showmessage(s);
end;
end.
在execute中写上我的函数。
请问我execute中函数的参数要怎么传递?全局变量?
比如:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
procedure test(s:string);
{ Private declarations }
public
{ Public declarations }
end;
type
TMyThread=class(TThread)
protected
procedure Execute;
override;
public
constructor create;
end;
var
Form1: TForm1;
ttest: TMyThread;
implementation
{$R *.dfm}
constructor TMyThread.create;
begin
inherited create(false);
freeonterminate:=true;//线程终止时自动删除对象
end;
procedure TMyThread.Execute;
begin
//test();
不知道这样写行不行。如果可以test的参数应该怎么传递。
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
ttest:=TMyThread.create;
end;
procedure TForm1.test(s: string);
begin
Showmessage(s);
end;
end.