请帮看这样的程序,怪啊?
我想写一个动态的线程,里面指做一件事,我的伪代码如下
unit Unit1;
uses Unit3;
procedure TForm1.DoGoData(var ithreadUseNO:string);
begin
heremycode;
end;
procedure TForm1.btnGoClick(Sender: TObject);
var mainthread1:TMutiThread;
begin
mainthread1:=TMutiThread.Create(false);
mainthread1.iLoop:=strtoint(edUser.text);
mainthread1.Resume;
end;
Unit3
unit Unit4;
interface
uses
Classes;
type
TMutiThread = class(TThread)
private
{ Private declarations }
protected
procedure Execute; override;
public
iLoop:integer;
function GetElapseTime :String;
constructor Create(tf:boolean);
end;
implementation
uses Unit1,Unit3,SysUtils;
{ Important: Methods and properties of objects in VCL or CLX can only be used
in a method called using Synchronize, for example,
Synchronize(UpdateCaption);
and UpdateCaption could look like,
procedure TMutiThread.UpdateCaption;
begin
Form1.Caption := 'Updated in a thread';
end; }
{ TMutiThread }
function TMutiThread.GetElapseTime :String;
begin
end;
constructor TMutiThread.create(tf:boolean);
begin
inherited Create(tf);
end;
procedure TMutiThread.Execute;
var i:integer;
Searcher:array [1..1000]of TMyThread;
begin
// SetLength(Searcher,iLoop);
for i:=1 to iloop do begin
Searcher[i]:=TMyThread.Create(false);
Searcher[i].threadUserID:= inttostr(I);
Searcher[i].resume;
end;
for i:=1 to iloop do begin
Searcher[i].WaitFor;
end;
end; { Place thread code here }
end.
unit Unit2;
interface
uses
Classes;
type
TMyThread = class(TThread)
private
{ Private declarations }
protected
procedure Execute; override;
procedure doData;
constructor Create(tf:boolean);
public
threadUserID:string;
end;
implementation
{ Important: Methods and properties of objects in VCL or CLX can only be used
in a method called using Synchronize, for example,
Synchronize(UpdateCaption);
and UpdateCaption could look like,
procedure TMyThread.UpdateCaption;
begin
Form1.Caption := 'Updated in a thread';
end; }
{ TMyThread }
procedure TMyThread.doData;
begin
form1.DoGoData(threadUserID);
end;
procedure TMyThread.Execute;
begin
Synchronize(doData);
{ Place thread code here }
end;
constructor TMyThread.create(tf:boolean);
begin
inherited Create(tf);
end;
end.
这样合理吗?