Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to add a property to a component that will reflect on the object inspector

in Delphi 7 , when adding a propery to an object, how is it possible to see that property in the object inspector?

like image 626
none Avatar asked Nov 30 '22 04:11

none


2 Answers

Make the property published. For instance,

private
  FMyProperty: integer;
published
  property MyProperty: integer read FMyProperty write FMyProperty;

Often, you need to repaint the control (or do some other processing) when a property is changed. Then you can do

private
  FMyProperty: integer;
  procedure SetMyProperty(MyProperty: integer);
published
  property MyProperty: integer read FMyProperty write SetMyProperty;

...

procedure TMyControl.SetMyProperty(MyProperty: integer);
begin
  if FMyProperty <> MyProperty then
  begin
    FMyProperty := MyProperty;
    Invalidate; // for example
  end;
end;
like image 67
Andreas Rejbrand Avatar answered Dec 04 '22 07:12

Andreas Rejbrand


Add that property to the published section, it will make it appear on the Object Inspector, like this:

TMyComponent = class(TComponent)
 ...
published
  property MyProperty: string read FMyProperty write SetMyProperty;
like image 33
jachguate Avatar answered Dec 04 '22 07:12

jachguate