加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

delphi – 为什么集中的MessageDlg会创建异常?

发布时间:2020-12-15 09:26:22 所属栏目:大数据 来源:网络整理
导读:德尔福6. 我实现了一个以所有者表单为中心的MessageDlg 正如@David Heffernan在2011年1月6日的建议. 2011年的原始问题在这里: How to make MessageDlg centered on owner form. 居中对话框有效一次. 在第一次抛出异常之后. – EAccessViolation – 地址0000
德尔福6.
我实现了一个以所有者表单为中心的MessageDlg
正如@David Heffernan在2011年1月6日的建议.

2011年的原始问题在这里:
How to make MessageDlg centered on owner form.

居中对话框有效一次.
在第一次抛出异常之后.
– EAccessViolation
– 地址00000000的访问冲突
– 读取地址00000000

我可能做错了什么?

function TEthernetNodes_form.CenteredMessageDlg(const Msg: string;
                                                DlgType:   TMsgDlgType;
                                                Buttons:   TMsgDlgButtons;
                                                HelpCtx:   Integer): Integer;
// Open a message Dialog in the center of the owner form
var
  Dialog: TForm;
begin
  Result := mrNo; // Suppress linker warning
  try
    Dialog := CreateMessageDialog(Msg,DlgType,Buttons);
    try
      Self.InsertComponent(Dialog);
      Dialog.Position := poOwnerFormCenter;
      Result := Dialog.ShowModal
    finally
      Dialog.Free
    end;

  except on E: Exception do
               begin
                 AddToActivityLog('Exception in CenteredMsgDlg: [' +  
                                   string(E.ClassName) + ']' +  
                                   E.Message,True,True);  
                 //Tried "ShowMEssage" instead of AddToActivityLog here. Does not display.
               end;

  end;
end;  

procedure TEthernetNodes_form.Button1Click(Sender: TObject);
begin
  CenteredMessageDlg('Test CenteredMessageDlg.',mtConfirmation,[mbOK],0);
end;

我的活动日志中显示了异常,如下所示:

Exception in CenteredMsgDlg: [EAccessViolation] Access violation at  
address 00000000. Read of address 00000000

解决方法

CreateMessageDialog使用Application作为其所有者创建表单 – 它将添加到应用程序组件列表中.使用Self.InsertComponent(Dialog);您将它添加到您的表单组件列表,但它不会从应用程序中删除.

var
  Dialog: TForm;
begin
  Result := mrNo; // Suppress linker warning
  try
    Dialog := CreateMessageDialog(Msg,Buttons);
    try
      Application.RemoveComponent(Dialog); // remove Dialog from Application components
      Self.InsertComponent(Dialog);
      Dialog.Position := poOwnerFormCenter;
      Result := Dialog.ShowModal;
    finally
      Dialog.Free
    end;

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读