[英]how to make custom component property?
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. 就像TPicture一样。
any Idea or suggestions? 任何想法或建议?
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: 如果您的类被用作其他组件的属性,并且您想使用Object Inspector来调用对话框,那么您必须实现并注册自定义属性编辑器,例如:
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;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.