如何制作自定义组件属性?

6
我需要帮助制作一个控件属性,当您单击它时,弹出一个自定义对话框,就像设置一样。就像TPicture一样。 有什么想法或建议吗?

+1不知道为什么有人给一个好问题点踩。 - David Heffernan
@David:最近的所有Delphi问题都有一个负投票,而没有任何关于为什么的评论。也许有人不理解箭头的作用? :) - Wouter van Nifterick
1个回答

9

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

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;

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接