Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

any Idea or suggestions?

like image 456
XBasic3000 Avatar asked Jan 21 '12 12:01

XBasic3000


1 Answers

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;
like image 148
Remy Lebeau Avatar answered Sep 28 '22 07:09

Remy Lebeau