T
tswhoney
Unregistered / Unconfirmed
GUEST, unregistred user!
请看我的代码,请问execute过程何时执行?
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
ListBox1: TListBox;
procedure Button1Click(Sender: TObject);
private
procedure threadsdone(Sender:tobject);
{ Private declarations }
public
{ Public declarations }
end;
tfoothread=class(tthread)
protected
procedure execute;override;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
const
maxsize=128;
var
nextnumber:integer=0;
doneflags:integer=0;
globalarray:array[1..maxsize] of integer;
function getnextnumber:integer;
begin
result:=nextnumber;
inc(nextnumber);
end;
procedure tfoothread.execute;
var
i:integer;
begin
onterminate:=form1.threadsdone;
for i:=1 to maxsizedo
begin
globalarray:=getnextnumber;
sleep(5);
end;
end;
procedure tform1.threadsdone(sender:tobject);
var
i:integer;
begin
inc(doneflags);
ifdo
neflags=2 then
for i:=1 to maxsizedo
listbox1.Items.Add(inttostr(globalarray));
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
tfoothread.Create(false);
tfoothread.Create(false);
end;
end.
按钮中并没有调用,是如何调用execute?
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
ListBox1: TListBox;
procedure Button1Click(Sender: TObject);
private
procedure threadsdone(Sender:tobject);
{ Private declarations }
public
{ Public declarations }
end;
tfoothread=class(tthread)
protected
procedure execute;override;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
const
maxsize=128;
var
nextnumber:integer=0;
doneflags:integer=0;
globalarray:array[1..maxsize] of integer;
function getnextnumber:integer;
begin
result:=nextnumber;
inc(nextnumber);
end;
procedure tfoothread.execute;
var
i:integer;
begin
onterminate:=form1.threadsdone;
for i:=1 to maxsizedo
begin
globalarray:=getnextnumber;
sleep(5);
end;
end;
procedure tform1.threadsdone(sender:tobject);
var
i:integer;
begin
inc(doneflags);
ifdo
neflags=2 then
for i:=1 to maxsizedo
listbox1.Items.Add(inttostr(globalarray));
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
tfoothread.Create(false);
tfoothread.Create(false);
end;
end.
按钮中并没有调用,是如何调用execute?