从VCL中将delphi中的属性暴露给C++

Zer*_*oth 2 c++ delphi c++builder

EnumAllWindowsOnActivateHint是TApplication的一个属性,根据帮助,应该在C++ Builder - Codegear 2007中公开.事实并非如此.

我的困难在于我需要将它暴露给C++,或者为我的应用程序将其设置为true.

因此,有不同的途径来实现这一点,我尝试过的事情可能做错了:

  1. Forms.pas中暴露的EnumAllWindowsOnActivateHint.但是,我很难将此更改包含在应用程序/ VCL中.我已经尝试了重新编译VCL的所有内容.没有任何效果.
  2. 调用一些可以从C++访问该属性的delphi代码.
  3. 别的什么?

我无法升级到较新版本的Codegear,因为这会破坏应用程序所依赖的RTTI行为.

建议?解决方案?

Rem*_*eau 6

TApplication::EnumAllWindowsOnActivateHint在C++ Builder 2009之前,它不是作为真正的C++可访问属性引入的.在C++ Builder 2007中,它实现为类助手的属性:

TApplicationHelper = class helper for TApplication
private
  procedure SetEnumAllWindowsOnActivateHint(Flag: Boolean);
  function GetEnumAllWindowsOnActivateHint: Boolean;
  ...
public
  property EnumAllWindowsOnActivateHint: Boolean read GetEnumAllWindowsOnActivateHint write SetEnumAllWindowsOnActivateHint;
  ...
end;
Run Code Online (Sandbox Code Playgroud)

类助手是Delphi特有的功能,无法在C++中访问.所以你必须使用一种解决方法.创建一个单独的.pas文件,公开C风格的函数来访问该 EnumAllWindowsOnActivateHint属性,然后将该.pas文件添加到您的C++项目中:

AppHelperAccess.pas:

unit AppHelperAccess;

interface

function Application_GetEnumAllWindowsOnActivateHint: Boolean;
procedure Application_SetEnumAllWindowsOnActivateHint(Flag: Boolean);

implementation

uses
  Forms;

function Application_GetEnumAllWindowsOnActivateHint: Boolean;
begin
  Result := Application.EnumAllWindowsOnActivateHint;
end;

procedure Application_SetEnumAllWindowsOnActivateHint(Flag: Boolean);
begin
  Application.EnumAllWindowsOnActivateHint := Flag;
end;

end.
Run Code Online (Sandbox Code Playgroud)

编译时,将生成一个C++ .hpp头文件,然后您的C++代码可以用来调用这些函数.例如

#include "AppHelperAccess.hpp"

void EnableEnumAllWindowsOnActivateHint()
{
    Application_SetEnumAllWindowsOnActivateHint(true);
}

void DisableEnumAllWindowsOnActivateHint()
{
    Application_SetEnumAllWindowsOnActivateHint(false);
}

void ToggleEnumAllWindowsOnActivateHint()
{
    bool flag = Application_GetEnumAllWindowsOnActivateHint();
    Application_SetEnumAllWindowsOnActivateHint(!flag);
}
Run Code Online (Sandbox Code Playgroud)