How to create a component property that lists other components?

浪尽此生 提交于 2019-12-02 00:29:28

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;

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.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!