delphi窗体调用过程中出现access violation,请高手帮忙
procedure TForm1.Button1Click(Sender: TObject);var user,temp:string;
begin
user:=Edit1.Text;
temp:='';
DataModule1.ADOQuery1.Close;
DataModule1.ADOQuery1.SQL.Clear ;
DataModule1.ADOQuery1.SQL.Text:=('select 门诊编号 from 门诊挂号表 where 门诊编号='''+user+'''');
DataModule1.ADOQuery1.Open;
temp:=DataModule1.ADOQuery1.FieldByName('门诊编号').AsString ;
if temp<>''then
Form5.ShowModal
else
showmessage('输入错误,请重新输入!');
end; 这个错误是不是一启动就出现的?如果是,那么就是在Options中调整一下创建顺序就可以了. 不是的,顺序没问题,Button1的caption属性是正确,如果输入错误值可以正确判断,把调用窗体改为showmessage也能正常运行,就是一输入正确值,调用窗体就出错。 Application.createForm(TForm5,Form5);
Form5.ShowModal
试试 好了,问题解决了,太感谢你了,我已经研究好几天了。 其实窗体也最好把他看成一个类,
因为delphi提供了继承窗体这样的概念,
所以最好是在将form5.showmodal改为
if not Assigned(Form5) then
begin
Form5 := TForm5.Create(Application);
Form5.ShowModal;
end
else
Form5.BringToFront;
这个访问违例的错误提示非常极其以及十分不友好
[quote]temp:=DataModule1.ADOQuery1.FieldByName('门诊编号').AsString ;if temp<>''then
...[/quote]
判断查询结果是否为空,最好不要用这种方法。
[color=Red]if DataModule1.ADOQuery1.RecordCount>0 then [/color]// RecordCount 为数据集的记录数
...
else
... 谢谢大家的指点,收益匪浅
页:
[1]
