how to make custom component property?

人盡茶涼 提交于 2019-12-10 13:22:48

问题


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.

any Idea or suggestions?


回答1:


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:

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;


来源:https://stackoverflow.com/questions/8953083/how-to-make-custom-component-property

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!