【问题标题】:how to make custom component property?如何制作自定义组件属性?
【发布时间】:2012-02-15 16:58:51
【问题描述】:

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

有什么想法或建议吗?

【问题讨论】:

  • +1 不知道为什么有人反对一个好问题
  • @David:不知何故,最近所有的 Delphi 问题都被否决了,没有任何评论为什么......也许有人不明白箭头的用途? :)

标签: delphi properties components custom-controls


【解决方案1】:

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

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;

【讨论】:

    猜你喜欢
    • 2019-12-06
    • 1970-01-01
    • 2021-03-20
    • 1970-01-01
    • 2011-01-12
    • 1970-01-01
    • 2014-02-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多