如何制作自定义组件属性?
Posted
技术标签:
【中文标题】如何制作自定义组件属性?【英文标题】:how to make custom component property? 【发布时间】:2012-02-15 16:58:51 【问题描述】:我需要帮助来制作一个控件属性,当您单击它时,它会弹出一个自定义对话框,如设置。就像 TPicture 一样。
有什么想法或建议吗?
【问题讨论】:
+1 不知道为什么有人反对一个好问题 @David:不知何故,最近所有的 Delphi 问题都被否决了,没有任何评论为什么......也许有人不明白箭头的用途? :) 【参考方案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;
【讨论】:
以上是关于如何制作自定义组件属性?的主要内容,如果未能解决你的问题,请参考以下文章