5

In the Delphi IDE, some components in Delphi have the ability to "add" properties to the child controls they contain in the property editor.

How can I achieve the same thing with my own TCustomPanel descendant?

Some more details:

What I want to achieve is the following: I have a very complex configuration dialog for an application with a large number of visual components.

I want to add to each of these components a "complexity index" (an integer) that will be used to show or hide the component based on a selection made by the user (a dropdown with "simple", "advanced" and "expert" options).

I understand that the property will actually belong to the parent panel but I need a way to display it, in the IDE, as if it was attached to the control it is related to.

The perfect exemples are the various "organizational" panels provided by Delphi: TGridPanel and TRelativePanel. Each of these have a ControlCollection (published) properties that is used to hold the actual states of the additional properties but I failed to locate how the property editor knows that it must attach the properties to the child controls.

Here is a screenshot of a TLabel placed inside a TRelativePanel with the relevant properties highlighted: Screenshot of the property editor with "additional" properties displayed for a TLabel component placed inside a TRelativePanel

Community
  • 1
  • 1
Stephane
  • 3,173
  • 3
  • 29
  • 42
  • 2
    Components are compiled code, they can't actually add new properties dynamically, especially to other components. What is most likely happening is a custom property editor is registered at design time to manipulate the entries of the Object Inspector, not the components themselves. – Remy Lebeau Dec 27 '17 at 07:24
  • I'm talking about the editing of the components in the IDE. I have added a more detailed explanation of what I would like to achieve. – Stephane Dec 27 '17 at 07:43
  • Why is my question downvoted? if you downvote it, at the very least please explain why – Stephane Dec 27 '17 at 07:44
  • I don't have Delphi-10 at hand. can you maybe show a picture of how it looks in the IDE? do you mean that when you click/select a child control of the panel, the IDE shows an extra property for that *selected control*? or do you see the extra properties in the control collection editor? – kobik Dec 27 '17 at 08:39
  • 1
    What amazes me is why such an unclear question receives multiple up votes. – David Heffernan Dec 27 '17 at 08:48
  • @DavidHeffernan What do you fail to understand in my question? – Stephane Dec 27 '17 at 09:03
  • 2
    @kobik I have added a screenshot. Hopefully, it makes it clearer – Stephane Dec 27 '17 at 09:03
  • The screen shot now makes it clearer – David Heffernan Dec 27 '17 at 09:04
  • 1
    Like I said, this is done with custom property editors. It is not that hard to register an editor for all `TControl` descendants and then have the editor check the type of a selected control's `Parent` at design-time before creating extra pseudo properties in the Object Inspector. – Remy Lebeau Dec 27 '17 at 21:56
  • 1
    a comment from TCustomRelativePanel.ControlCollection property sources: This property is defined as published in order to support the TSelectionEditor descendant that is responsible for adding the set of new properties to child controls. The custom selection editor also removes the ControlCollection property from the Object Inspector. I looked at TSelectionEditor help but cannot see how this could be achieved without some sort of Embarcadero magic. And I have to say this relative panel is a complete surprise to me - WOW, Borland spirit is not deat yet ! – Peter Aug 24 '18 at 15:21
  • 1
    ah, here is the magic :) http://edn.embarcadero.com/article/33448 – Peter Aug 24 '18 at 15:45
  • 1
    https://web.archive.org/web/20190905085626/edn.embarcadero.com/article/33448 – George Birbilis Nov 02 '21 at 23:13

0 Answers0