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

XBa*_*000 6 delphi components properties custom-controls

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

任何想法或建议?

Rem*_*eau 8

如果您的类被用作其他组件的属性,并且您想使用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;
Run Code Online (Sandbox Code Playgroud)