如何创建一个列出其他组件的组件属性? [英] How to create a component property that lists other components?

查看:126
本文介绍了如何创建一个列出其他组件的组件属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

SynEdit组件具有属性荧光笔,其中包含一个下拉列表,其中列出了所有当前存在的荧光笔(设计时间)。对我来说,这似乎是设计时组件的一个非常重要的概念,但是我根本找不到它的工作原理:

The SynEdit component has the property "Highlighter", which contains a dropdown-list in which all the currently existant Highlighters are listed (design-time). To me this seems like a very important concept for design-time components, but I'm simply unable to find out how it works:

我们假设你下载了一个TSynEdit和一个TSynPasSyn到您的表单。然后单击具有Highlighter属性的TSynedit。您现在可以选择先前创建的TSynPasSyn。如果您创建另一个TSynPasSyn,它也将添加到此列表。我的问题:

Let's assume you drop down a TSynEdit and a TSynPasSyn onto your form. Then you click the TSynedit which has the property Highlighter. You are now able to select the previously created TSynPasSyn. If you create another TSynPasSyn, it will be added to this list too. My question:

哪些是在自己的组件中做这样的事情的最佳方法?你可以简单地使用一个属性编辑器,还是需要自定义的helper类,或是完全不同的东西?

Which is the best way to do such a thing in your own component? Can you simply use a property editor or do you need custom helper-classes, or something completely different?

推荐答案

您,但是不需要在您自己的组件中的组件属性的属性编辑器中列出现有组件。只需将该属性声明为所需类型,VCL框架就可以执行其他操作。

Maybe this will surprise you, but nothing is required to get existing components listed in the property editor of a component property in your own component. Just declare the property as the desired type, and the VCL framework will do the rest.

例如,考虑这个非常简单的组件:

For example, consider this very simple component:

type
  TButtonSelector = class(TComponent)
  private
    FButton: TButton;
  published
    property Button: TButton read FButton write FButton;
  end;

在IDE中安装此组件后,在对象检查器中选择Button属性时,所有现有列出了当前窗体中的按钮。

After installing this component in the IDE, when you select the Button property in the Object Inspector, all existing buttons on the current Form are listed.

这些都是以 DesignEditors.TComponentProperty 构建,这意味着只需要让您想从 TComponent 中选择下降的对象。

This is all build in in DesignEditors.TComponentProperty, which means that the only requirement is to let the object you want to select descent from TComponent.

这篇关于如何创建一个列出其他组件的组件属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆