如何在 VCL 组件的派生类中隐藏继承的 __published 属性?

发布于 2024-08-25 08:01:18 字数 426 浏览 4 评论 0原文

我基于现有的 VCL 组件创建了一个新的 VCL 组件。我现在想要做的是从 ini 文件而不是属性检查器设置密码和用户名属性。

Robert Dunn Link

我在上面的 delphi 论坛上读到,你无法取消发布属性,唯一的解决方法是将属性重新声明为只读。我尝试了这个,但它所做的只是使属性只读并在对象检查器中变灰。虽然这可行,但我更希望该属性根本不可见。

__property System::UnicodeString 密码 = {read=FPassword};

预先感谢您提供任何帮助或 C++ VCL 组件编写教程的链接。我用的是CB2010

I have created a new VCL component based on an existing VCL component. What I want to do now is set the Password and Username properties from an ini file instead of the property inspector.

Robert Dunn Link

I read on the delphi forum above you cannot unpublish a property and that the only workaround is to redeclare the property as read-only. I tried this but it all it does is make the property read only and grayed out in the object inspector. While this could work I would prefer if the property wasn't visible at all.

__property System::UnicodeString Password = {read=FPassword};

Thanks in advance for any help or links to c++ VCL component writing tutorials. I am using CB2010

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

木槿暧夏七纪年 2024-09-01 08:01:18

查找DesignIntf​​.UnlistPublishedProperty。请参阅此步骤

Look up DesignIntf.UnlistPublishedProperty. See this tread.

七七 2024-09-01 08:01:18

定义的语言不允许您隐藏已发布的属性。

我会使用聚合而不是继承,即创建一个新的 VCL 组件,将其方法委托给现有组件,然后您就可以完全控制要发布的属性。

The language as defined will not allow you to hide published properties.

I would make use of aggregation instead of inheritance i.e. Create a new VCL component that delegates its methods to the existing component, you then have full control over what properties to publish.

淡紫姑娘! 2024-09-01 08:01:18

我知道这是一个老问题,但仍然没有关于如何执行此操作的良好文档。我自己最终来到这里试图解决这个问题,并认为其他人出于同样的原因来到这里应该得到关于如何做到这一点的解释。

在撰写本文时,我使用的是 C++ Builder 10.4(悉尼)。

有一个名为 designide 的包,您需要将其添加为项目的引用。

  1. 在您的包项目中,右键单击“Requires”并选择“Add Reference...”
  2. 单击“Browse”按钮并转到您的安装文件夹,在 lib\ 中查找 designide.bpi win32\releaselib\win64\release 取决于您的目标。

还必须更新包含路径,以便它可以找到头文件。

  1. 右键单击您的包项目并选择“选项”
  2. 选择“共享选项”
  3. 为了方便起见,将“目标”设置为“所有配置 - 所有平台”。
  4. 选择“包含路径”并单击“...”以编辑值。
  5. 添加行 $(BDSINCLUDE)\windows\vcl\design
  6. 单击“确定”按钮,然后保存更改。

在您的代码中添加 #include 并使用函数 UnlistPublishedProperty() 取消发布包函数 Register() 中的属性。

void __fastcall PACKAGE Register() {

    // Register components
    TComponentClass classes[1] = {__classid(TMyVCLClass)};
    RegisterComponents(L"MyComponent", classes, 0);

    // Unpublish properties
    UnlistPublishedProperty(__classid(TMyVCLClass),L"AlignWithMargins");
    UnlistPublishedProperty(__classid(TMyVCLClass),L"Margins");
}

I know this is an old question, but there is still no good documentation on how to do this. I ended up here myself trying to figure this out and thought that others ending up here for the same reason deserve an explanation on how to do this.

In the writing moment, I'm using C++ Builder 10.4 (Sydney).

There is a package called designide that you need to add as a reference to your project.

  1. In your package project, right click on "Requires" and select "Add Reference..."
  2. Click the "Browse" button and go to your install folder look for designide.bpi in lib\win32\release or lib\win64\release depending on your target.

The include path must also be updated so it can find the header file.

  1. Right click on your package project and select "Options"
  2. Select "Shared Options"
  3. For convenience, set "Target" to "All configurations - All platforms".
  4. Select "Include path" and click on the "..." to edit the value.
  5. Add the line $(BDSINCLUDE)\windows\vcl\design
  6. Click the Ok button and then save the changes.

In your code add #include <DesignIntf.hpp> and use the function UnlistPublishedProperty() to unpublish properties in your package function Register().

void __fastcall PACKAGE Register() {

    // Register components
    TComponentClass classes[1] = {__classid(TMyVCLClass)};
    RegisterComponents(L"MyComponent", classes, 0);

    // Unpublish properties
    UnlistPublishedProperty(__classid(TMyVCLClass),L"AlignWithMargins");
    UnlistPublishedProperty(__classid(TMyVCLClass),L"Margins");
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文