码迷,mamicode.com
首页 > 其他好文 > 详细

报错'cannot change visible in onshow or onhide'

时间:2017-06-26 13:40:12      阅读:326      评论:0      收藏:0      [点我收藏+]

标签:错误   需要   admin   message   pool   hid   text   where   窗口   

问题描述:

关闭程序的时候需要修改modalresult值,

原来把加载的事件写在MailForm的onshow事件里总是报‘cannot change visible in onshow or onhide‘;

技术分享

解决方法:

不要把事件写在onshow里面,改到oncreate事件里即可:

技术分享

 

关闭窗体通过修改modalresult值的方法:

procedure TFLogin.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
if Self.ModalResult=mrCancel then
 begin
 if MessageDlg(确定要退出?,mtConfirmation,[mbYes,mbNo],0)=mryes then
 begin
 Self.close;
 Application.Terminate
 end
 else
 Self.ModalResult:=0;
 end;
end;
procedure TFLogin.btn2Click(Sender: TObject);
begin
 if MessageDlg(确定要退出?,mtConfirmation,[mbYes,mbNo],0)=mryes then
 begin
 Self.ModalResult:=mrCancel;  //关闭窗体
 Application.Terminate;   //结束程序
 end
else
 Self.ModalResult:=0;   //停留在登陆窗口
end;

 

登录窗体,登陆成功判断并修改modalresult:

procedure TFLogin.btn1Click(Sender: TObject);
begin
with frmDataPool.qry用户账号表 do
begin
  Close;
  SQL.Text:=select * from 用户账号表 where admid = :admid ;
  Parameters.ParamByName(admid).Value:=edtAdmid.Text;    //为admin参数赋值;
  Open;
end;
  if frmDataPool.qry用户账号表[admps]=null then  //如果账号查找不到,说明账号错
  begin
    ShowMessage(账号不存在);
    Exit;
  end;
  if frmDataPool.qry用户账号表[admps] <> edtadmps.Text then
  begin
    ShowMessage(密码错);
    exit;
  end;
  Self.ModalResult:=mrOk;//对话框mrok返回
  ShowMessage(登录成功!);

end;

 参考答案:http://www.rwtext.com/text.asp?id=9731

 

【编译错误解析】提示Cannot change Visible in OnShow or OnHide 的原因及解决方法

Cannot change Visible in OnShow or OnHide 的意思是:不能在 OnShow 或OnHide事件中修改显示状态

OnShow ,OnHide 本身就是指定显示与否,不可以在这样的事件中用.Visible .

就比如吧Onshow中你用Form1.Visible := False , 事让窗体在显示的时候不显示,你这不是让编译器为难么?

这就是为什么可以在OnCreate中用,不能在OnShow中用.

 

报错'cannot change visible in onshow or onhide'

标签:错误   需要   admin   message   pool   hid   text   where   窗口   

原文地址:http://www.cnblogs.com/ddxxxb/p/7079861.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!