Can a component editor run on multiple components?

Short version

I am trying to implement my first component editor for a custom button that I created. With some online articles, I have successfully installed the editor and see a menu item when I right-click on my button in Designer Design.

But this component editor menu does not appear when more than one button control is selected.

Do Component Editors only develop selected individual controls by default, or can they work with several selected controls, and if so, how?

Long version

I was in the process of implementing TPropertyEditor for one of my own components, but now decided that TComponentEditor would be better served, or so I thought.

Basically, I have TCustomButton, which I have, this button component has several published properties for changing the appearance, for example, border and fill color, etc.

Component Editor I am implementing the display of the new menu item "Load settings from file" in the context menu. When a simple TOpenDialog is executed, you can select the appropriate file, for example, the Ini file, which I then read, and set the values ​​from the file accordingly.

Everything works well from what I can see, but since I'm still a newbie and dealing with all of the Delphi user control part, I noticed that something is not happening - I'm not sure if it really is or I can change it.

The problem is using the component editor menu in several selected instances of the button control. If only one button is selected, and I right-click in the designer, my menu is displayed at the top of the context menu, however, several selected controls do not display the component editor menu.

Code example

type TMyButtonEditor = class(TComponentEditor) public procedure ExecuteVerb(Index: Integer); override; function GetVerb(Index: Integer): string; override; function GetVerbCount: Integer; override; end; implementation { TMyButtonEditor } procedure TMyButtonEditor.ExecuteVerb(Index: Integer); var OpenDialog: TOpenDialog; begin case Index of 0: begin OpenDialog := TOpenDialog.Create(nil); try OpenDialog.Filter := 'All Files (*.*)|*.*'; if OpenDialog.Execute then begin // handle opened file.. end; finally OpenDialog.Free; end; end; end; end; function TMyButtonEditor.GetVerb(Index: Integer): string; begin case Index of 0: begin Result := 'Load settings from File...'; end; end; end; function TMyButtonEditor.GetVerbCount: Integer; begin Result := 1; end; 

In the registration procedure block:

 RegisterComponentEditor(TMyButton, TMyButtonEditor); 

From what I see, only individual components can use the Component Editor at any given time, or am I mistaken, and they can be used on several controls?

I was hoping to select maybe 3 or 4 of my buttons in the form designer and use the component editor to apply the imported settings to these buttons at the same time.

+2
delphi custom-controls
source share
1 answer

Component editors can only work with one component.

This is one of the very important reasons, whenever possible, to offer properties available through the Object Inspector, rather than component editors. Because the Object Inspector can work with several components at once.

+4
source share

All Articles