我做过一个动态生成线程并同时生成一个动态窗体供它使用;
下面是结构;但愿你用的上
**********************************************
unit viewthread;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,main,
StdCtrls, Grids, ValEdit, DBTables, DB, ADODB, ComCtrls;
type {首先定义窗体对象}
Tqurform = class(TForm)
Label1: TLabel;
ProgressBar1: TProgressBar;
ADOQuery1: TADOQuery;
ADOConnection1: TADOConnection;
Memo: TMemo;
......
procedure FormClose(Sender: TObject;
var Action: TCloseAction);
private
{ Private declarations }
public
{ Public declarations }
end;
procedure newqur(qurnum : integer;
pro :string;
dt :TDate);
implementation
uses
vsl_rs,field_rs,out_vech_rs,berth_using_rs,gate_using_rs,cntr_turnover_rs,dr_vsl_rs;
{$R *.dfm}
type {然后再定义线程对象}
TAdoqueryThread =class(TThread)
private
Ffr :Tqurform;
//窗体变量
procedure runseccess;
procedure runfailled;
protected
procedure Execute;override;
public
constructor creat(qurnum : integer;
pro:string;dt :TDate);virtual;
destructor Destroy;override;
end;
destructor TAdoqueryThread.Destroy;
begin
......
Ffr.Close;
inherited Destroy;
end;
constructor TAdoqueryThread.creat(qurnum : integer;
pro:string;dt :TDate);
begin
inherited Create(true);
//在线程中创建窗体
Ffr:=viewthread.Tqurform.Create(application);
Ffr.name:=Ffr.name+inttostr(qurnum);
Ffr.Show;
......
freeonTerminate:=true;
resume;
end;
procedure TAdoqueryThread.Execute;
begin
try
.....
synchronize(runseccess);
except
synchronize(runfailled);
end;
end;
procedure TAdoqueryThread.runseccess;
begin
{当线程调用成功时....}
end;
procedure TAdoqueryThread.runfailled;
begin
{当线程调用失败时....}
end;
procedure Tqurform.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
{线程结束时释放内存.....}
end;
{用于在主线程中调用辅线程}
procedure newqur(qurnum : integer;
pro :string;dt :TDate);
begin
{创建一个新的线程运行状态窗口}
TAdoqueryThread.creat(qurnum,pro,dt);
end;
end.