public
procedure setparams(sql:string);
end;var
Frm_Tyxg: TFrm_Tyxg;
v_sql:string;
implementation
uses u_chaxun;
{$R *.dfm}
procedure TFrm_Tyxg.setparams(sql:string);
begin
v_sql:=sql;
end;
procedure TFrm_Tyxg.Label5Click(Sender: TObject);begin
if Frm_chaxun = nil then
Frm_chaxun := TFrm_Chaxun.Create(Application);
Frm_chaxun.show;
end;
然后在查询的窗体的查找按钮中写了这样的程序:
if Frm_Tyxg = nil then
Frm_Tyxg := TFrm_Tyxg.create(Application);
Frm_Tyxg.Show;
Frm_Tyxg.setparams(sql_str);
procedure setparams(sql:string);
end;var
Frm_Tyxg: TFrm_Tyxg;
v_sql:string;
implementation
uses u_chaxun;
{$R *.dfm}
procedure TFrm_Tyxg.setparams(sql:string);
begin
v_sql:=sql;
end;
procedure TFrm_Tyxg.Label5Click(Sender: TObject);begin
if Frm_chaxun = nil then
Frm_chaxun := TFrm_Chaxun.Create(Application);
Frm_chaxun.show;
end;
然后在查询的窗体的查找按钮中写了这样的程序:
if Frm_Tyxg = nil then
Frm_Tyxg := TFrm_Tyxg.create(Application);
Frm_Tyxg.Show;
Frm_Tyxg.setparams(sql_str);
看了你的部分程序后,原来问题不是出在变量的窗体间传递上,而是你在进行delphi中窗体动态创建和释放中出现了问题。在Tfrm_Tyxg的label5click过程中动态创建了Tfrm_chaxun的实例,但在Tfrm_chaxun的查找按钮事件中又创建了一次Tfrm_Tyxg的实例,而在此之前,Tfrm_Tyxg的实例已存在,所以你要释放两次。据我所知,要完全释放一个窗体实例,需用FreeAndNil(窗体实例名)函数,一般在窗体的onclose事件中使用,单单用close是无法释放窗体实例指针的,再次create时会发生内存错误。
function getparams:string;
用来返回当前查询窗体设置的查询,然后在统一窗体中代码修改如下:var
Frm_Tyxg: TFrm_Tyxg;
v_sql:string;
implementation
uses u_chaxun;
{$R *.dfm}
procedure TFrm_Tyxg.Label5Click(Sender: TObject);begin
with tFrm_chaxun.create(self) do
begin
showmodal;
v_sql:=getparams;
{
/////处理刷新。
}
Free;
end;
end;
查询的窗体的查找按钮中:
close;