Snakeguo(楠): 没有说执行到哪一行报错,没有显示语法错误,而是整体运行的错误. wolfAone(¤一步一步网上爬¤) : weizhi(行者) : Thank you
我把程序这样改了之后,在Form2.Showmodal上显示上面的错误. ...... procedure TForm1.Button1Click(Sender: TObject); begin adoquery1.close; adoquery1.sql.clear;if RadioGroup1.ItemIndex=0 then adoquery1.sql.add('select * from nan_one'); if RadioGroup1.ItemIndex=1 then adoquery1.sql.add('select * from nan_two'); if RadioGroup1.ItemIndex=2 then adoquery1.sql.add('select * from nan_three'); if RadioGroup1.ItemIndex=3 then adoquery1.sql.add('select * from nan_four'); adoquery1.open;Form2.showmodal;end; ...... procedure TForm2.FormCreate(Sender: TObject);begin QuickRep1.Dataset:=Form1.adoQuery1; QRDBText1.Dataset:=Form1.adoQuery1; QRDBText1.Datafield:='student_ID'; end; ...... procedure TForm2.Formshow(Sender: TObject); being QuickRep.Preview; end; .....
把ADOQuery移到Form2上的话,那 procedure TForm1.Button1Click(Sender: TObject); begin adoquery1.close; adoquery1.sql.clear;if RadioGroup1.ItemIndex=0 then adoquery1.sql.add('select * from nan_one'); if RadioGroup1.ItemIndex=1 then adoquery1.sql.add('select * from nan_two'); if RadioGroup1.ItemIndex=2 then adoquery1.sql.add('select * from nan_three'); if RadioGroup1.ItemIndex=3 then adoquery1.sql.add('select * from nan_four');不是得改成Form2.ADOQuery1.SQL.Add拉????? 那ADOConnection是不是也要移到Form上呢?
begin
Form2.QuickRep1.preview; ---改成:Form2.Showmodal;
end;
在Form2.Show事件中写:
QuickRep1.preview;其实你这样结构不太好,造成了循环调用,还不用将AdOQuery等数据集控件放置到DataModule中,程序组织上就比较简单。
我想,如果你的Form1和Form2都是自动创建的话,那你的错误一定出在,下面这个函数里:
procedure TForm2.FormCreate(Sender: TObject);begin
Form2.QuickRep1.Dataset:=Form1.adoQuery1;
Form2.QRDBText1.Dataset:=Form1.adoQuery1;
Form2.QRDBText1.Datafield:='student_ID';
end;你不应该在TForm2这个类里引用Form2这相实例名,特别是在Create事件中.procedure TForm2.FormCreate(Sender: TObject);begin
QuickRep1.Dataset:=Form1.adoQuery1;
QRDBText1.Dataset:=Form1.adoQuery1;
QRDBText1.Datafield:='student_ID';
end;另外,你这样写的程序是十分依赖于Form1和Form2这两个变量了,而且这两个实例都必须在DPR文件中自动创建. 这也是一种非常不好的作法.好的风格是,在你要用到的地方才创建, 用完后就释放. 你自己改吧.
没有说执行到哪一行报错,没有显示语法错误,而是整体运行的错误.
wolfAone(¤一步一步网上爬¤) :
weizhi(行者) :
Thank you
......
procedure TForm1.Button1Click(Sender: TObject);
begin
adoquery1.close;
adoquery1.sql.clear;if RadioGroup1.ItemIndex=0 then
adoquery1.sql.add('select * from nan_one');
if RadioGroup1.ItemIndex=1 then
adoquery1.sql.add('select * from nan_two');
if RadioGroup1.ItemIndex=2 then
adoquery1.sql.add('select * from nan_three');
if RadioGroup1.ItemIndex=3 then
adoquery1.sql.add('select * from nan_four'); adoquery1.open;Form2.showmodal;end;
......
procedure TForm2.FormCreate(Sender: TObject);begin
QuickRep1.Dataset:=Form1.adoQuery1;
QRDBText1.Dataset:=Form1.adoQuery1;
QRDBText1.Datafield:='student_ID';
end;
......
procedure TForm2.Formshow(Sender: TObject);
being
QuickRep.Preview;
end;
.....
from2:=tform2.create(self);
form2.showmodel;
form2.free;
2)你将adoquery1移到form2上
procedure TForm1.Button1Click(Sender: TObject);
begin
adoquery1.close;
adoquery1.sql.clear;if RadioGroup1.ItemIndex=0 then
adoquery1.sql.add('select * from nan_one');
if RadioGroup1.ItemIndex=1 then
adoquery1.sql.add('select * from nan_two');
if RadioGroup1.ItemIndex=2 then
adoquery1.sql.add('select * from nan_three');
if RadioGroup1.ItemIndex=3 then
adoquery1.sql.add('select * from nan_four');不是得改成Form2.ADOQuery1.SQL.Add拉?????
那ADOConnection是不是也要移到Form上呢?
上有这个问题的加分!!!!!!!!
unit2中implementation下面
引用unit1
外面打adoquery1.Connection:=form1.ADOConnection1;
在一下,你注意一下form2的create里有和form1一样的事要作
所以form2不能自动创建,要手动创建
var
form2:Tform;
begin
form2:=tform2.create(self);
form2.showmodel;
end;
QuickRep.Preview;不要写在onshow里,
最好建立一个按钮,里面写上。
QuickRep.Preview;不要写在onshow里,
最好建立一个按钮,里面写上。
那我在Button1上的事件不是要改写成这样拉?
procedure TForm1.Button1Click(Sender: TObject);
begin
Form2.adoquery1.close;
Form2.adoquery1.sql.clear;
.......
但是改写成这样又显示什么不匹配之类的错误
如果写成With ADOQuery1 Do
有显示什么不期待With的出现
??????????????? dreamfan(★这个月辞职★) :
请说!!!!!!!
你在要在unit2中implementation下面
uses unit2
这个我当然加了
:(
我想错误估计不是这样吧
那类似于这种
Form2.adoquery1.close;
或是
With ADOQuery1 Do
可以这样用吗?
我用那个Button2来显示Form2的程序
procedure TForm1.Button2Click(Sender: TObject);
var form2:tform2;
begin
Form2:=TForm2.create(self);
Form2.QuickRep1.preview;
Form2.free;
end;
可是还是显示Form2和TForm2没有定义
就差这一点点
:(
我在http://www.csdn.net/expert/topic/788/788209.xml?temp=.4458124
上给你分!!!!!!!
万分感谢weizhi(行者), netlib(河外孤星) , rzh(小江西),wolfAone(¤一步一步网上爬¤) 的帮助,微薄小分,不成敬意!