从delphi代码调用C ++ builder XE Form

时间:2021-01-23 15:55:01

I'm using great TExceptionDialog from JEDI JCL package to show unhandled exceptions inside a C++ builder XE project, everything running ok so far. I've decided to enhance it a little bit by writing my own custom form to upload crash report to a server via FTP.

我正在使用来自JEDI JCL包的优秀TExceptionDialog来显示C ++构建器XE项目中未处理的异常,到目前为止一切正常运行。我决定通过编写自己的自定义表单来通过FTP将崩溃报告上传到服务器来增强它。

Problem is that I can't open my custom form from delphi PAS unit, tried to define as an external (no delphi programmer here, sorry :( ) but don't know how to properly code that. I've read lots of tutorials but couldn't find anything useful besides writing a DLL or an OLE container for my custom form, realy overkill for this project.

问题是我无法从delphi PAS单元打开我的自定义表单,试图将其定义为外部(这里没有delphi程序员,抱歉:()但是不知道如何正确编写代码。我已经阅读了很多教程但除了为我的自定义表单编写DLL或OLE容器之外,找不到任何有用的东西,真的对这个项目来说太过分了。

Question is, how can I properly execute this task? how to do ShowModal() of a form defined in a C++ unit, from a PAS delphi unit?

问题是,我该如何正确执行这项任务?如何从PAS delphi单元中执行C ++单元中定义的表单的ShowModal()?

1 个解决方案

#1


0  

I've found an easy and practical way of doing it, kinda ugly but works!

我找到了一种简单实用的方法,有点丑,但有效!

Trick is to get form by iterating thru all forms with Screen.Forms object. I've set TAG property for my form to a predefined number just to get an easy id of it.

通过使用Screen.Forms对象迭代所有表单来获取形式。我已经将我的表单的TAG属性设置为预定义的数字,只是为了获得它的简单ID。

In short, inside C++ unit of my form, I'll do this:

简而言之,在我的表单的C ++单元中,我会这样做:

MyForm->Tag=9999; // easy way of Iding my form

Then, inside my delphi unit of TExceptionDialog, in SEND button click method:

然后,在我的delphi单元TExceptionDialog中,在SEND按钮单击方法:

procedure TExceptionDialog.SendBtnClick(Sender: TObject);
var
   i: integer;
   form: TForm;
begin
  for i := 0 to Screen.FormCount-1 do // all forms
  begin
    form := Screen.Forms[i]; // get a form
    if(form.Tag = 9999) then // check if its my form
    begin
      form.ShowModal; // if its mine, call showmodal
      break;
    end;
  end;
  ModalResult := mrOk;  // return to my app
end;

#1


0  

I've found an easy and practical way of doing it, kinda ugly but works!

我找到了一种简单实用的方法,有点丑,但有效!

Trick is to get form by iterating thru all forms with Screen.Forms object. I've set TAG property for my form to a predefined number just to get an easy id of it.

通过使用Screen.Forms对象迭代所有表单来获取形式。我已经将我的表单的TAG属性设置为预定义的数字,只是为了获得它的简单ID。

In short, inside C++ unit of my form, I'll do this:

简而言之,在我的表单的C ++单元中,我会这样做:

MyForm->Tag=9999; // easy way of Iding my form

Then, inside my delphi unit of TExceptionDialog, in SEND button click method:

然后,在我的delphi单元TExceptionDialog中,在SEND按钮单击方法:

procedure TExceptionDialog.SendBtnClick(Sender: TObject);
var
   i: integer;
   form: TForm;
begin
  for i := 0 to Screen.FormCount-1 do // all forms
  begin
    form := Screen.Forms[i]; // get a form
    if(form.Tag = 9999) then // check if its my form
    begin
      form.ShowModal; // if its mine, call showmodal
      break;
    end;
  end;
  ModalResult := mrOk;  // return to my app
end;