6

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?

XBasic3000
  • 3,418
  • 5
  • 46
  • 91

1 Answers1

9

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;
NGLN
  • 43,011
  • 8
  • 105
  • 200
Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770