How to add a property to the component that will be displayed on the object inspector

in Delphi 7, when adding a property to an object, how can you see this property in the object inspector?

+4
source share
4 answers

Make the property published . For instance,

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

Often, when a property changes, you need to repaint the control (or do some other processing). 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; 
+14
source

Add this property to the published section, it will be displayed in the Object Inspector, for example:

 TMyComponent = class(TComponent) ... published property MyProperty: string read FMyProperty write SetMyProperty; 
+4
source

From docs :

The properties declared in the published section of the component class of the declaration can be edited in the Inspector object at design time.

+3
source

Do not forget that the Component must register in Delphi (preferably in the Time Time Package), or you will not see anything in the Object Inspector !!!

I mean ... I can create a new TPanel descendant called TMyPanel and add a new publishing property to it:

 type TPanel1 = class(TPanel) private FMyName: String; { Private declarations } protected { Protected declarations } public { Public declarations } published { Published declarations } property MyName : String read FMyName write FMyName; end; 

but this property will not be displayed in the Object Inspector if you have not registered a new class using RegisterComponent:

 procedure Register; begin RegisterComponents('Samples', [TPanel1]); end; 

Just to be complete :-)

+1
source

Source: https://habr.com/ru/post/1339248/


All Articles