如何制作自定义组件属性? [英] how to make custom component property?

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

问题描述

我需要帮助来制作一个控件属性,当您单击它时,它会弹出一个自定义对话框,如设置.就像 TPicture 一样.

I need help to make a control property that when you click on it, it pop-up a custom dialog like settings. just like the TPicture.

有什么想法或建议吗?

推荐答案

如果您的类被用作其他组件的属性,并且您想使用 Object Inspector 来调用您的对话框,那么您必须实现并注册一个自定义属性编辑器,例如:

If your class is used as a property of other components and you want to use the Object Inspector to invoke your dialog, then you have to implement and register a custom Property Editor, eg:

interface

uses
  DesignIntf, DesignEditors;

type
  TMyClassProperty = class(TPropertyEditor)
  public
    procedure Edit; override;
    function GetAttributes: TPropertyAttributes; override;
  end;

procedure Register;

implementation

uses
  MyClassUnit;

procedure TMyClassProperty.Edit;
begin
  with TMyDialog.Create(nil) do
  try
    ShowModal;
  finally
    Free;
  end;
end;

function TMyClassProperty.GetAttributes: TPropertyAttributes;
begin
  Result := inherited GetAttributes + [paDialog];
end;

procedure Register;
begin
  RegisterPropertyEditor(TypeInfo(TMyClass), nil, '', TMyClassProperty);
end;

这篇关于如何制作自定义组件属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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