奇哉,怪哉. 百思不得其解(100分)

  • 主题发起人 主题发起人 xf163
  • 开始时间 开始时间
X

xf163

Unregistered / Unconfirmed
GUEST, unregistred user!
form3是一个共用的参照(查找)客户档案的窗体,目的是用户双击后或选择确认后返回所选
客户...其数据源于Datamodule中.

unit Mainfrm;
...
procedure Tmainfrm.button1.Click(Sender: TObject);
begin
if not assigned(form1) then
begin
application.CreateForm(Tform1,form1);
try
form1.showmodal;
finally
form1.free;
form1:=nil;
end;
end
else
form1.Showmodal;
end;

procedure Tmainfrm.button2.Click(Sender: TObject);
begin
if not assigned(form2) then
begin
application.CreateForm(Tform2,form2);
try
form2.showmodal;
finally
form2.free;
form2:=nil;
end;
end
else
form.Showmodal;
end;

Unit form1;
public c_code:string;
procedure Tform1.button1click(..);
var sqlstring:string;
begin
c_code:='';
datamodule1.Customer.Active:=False;
if edit1.Text<>'' then
begin
sqlstring:='select * from customer where ccuscode like '+'''%'+ edit1.Text+'%''' ;
sqlstring:=sqlstring+' or ccusName like '+'''%'+ edit1.Text+'%''' ;
sqlstring:=sqlstring+' or ccusAbbName like '+'''%'+ edit1.Text+'%''' ;
end
else
sqlstring:='select * from customer where 1=1';
datamodule1.Customer.CommandText:= sqlstring;
datamodule1.customer.Active:=true;
if not assigned(form3) then
begin
application.CreateForm(Tform3,form3);
try
form3.showmodal;
finally
form3.free;
form3:=nil;
end;
end
else
form3.Showmodal;
...
c_code:=datamodule1.customer.fieldByname('ccusCode').asstring;
edit1.Text:=datamodule1.customer.fieldByname('ccusName').asstring;
end;

Unit form2;
procedure Tform2.button1click(..);
var sqlstring:string;
begin
c_code:='';
datamodule1.Customer.Active:=False;
if edit1.Text<>'' then
begin
sqlstring:='select * from customer where ccuscode like '+'''%'+ edit1.Text+'%''' ;
sqlstring:=sqlstring+' or ccusName like '+'''%'+ edit1.Text+'%''' ;
sqlstring:=sqlstring+' or ccusAbbName like '+'''%'+ edit1.Text+'%''' ;
end
else
sqlstring:='select * from customer where 1=1';
datamodule1.Customer.CommandText:= sqlstring;
datamodule1.customer.Active:=true;
if not assigned(form3) then
begin
application.CreateForm(Tform3,form3);
try
form3.showmodal;
finally
form3.free;
form3:=nil;
end;
end
else
form3.Showmodal;
...
c_code:=datamodule1.customer.fieldByname('ccusCode').asstring;
edit1.Text:=datamodule1.customer.fieldByname('ccusName').asstring;
end;

一模一样的代码, 从form1 调用Form3后,一切正常;
但从form2调用form3时,如果edit1.Text<>'' 则退出From3后,Form2也自动关闭.
如Form2.Text='' 则有时退出正常,有时Form2也自动关闭.
百思不得其解,请指教.


 
你用show 不要用模式表单
 
1.首先看你的代码里有没有CLOSE
2.看看你的BUTTON是不是其实一个bitbtn ,bitbtn的modalresult属性设置
3。无论如何 不要怀疑电脑
 
如果改为show 则Show后面的语句会先执行.退出时c_code永远是customer的第一条.
 
把所有button的modalresult属性设为mrNone试试
 
可怜的我,早就检查过modalresult,却只检查了Form3的,忘了Form1的Button1.
哈哈! 谢谢各位!
 
后退
顶部