Custom PropertyEditors - they never show up

Information

It seems to me completely unimportant how I manage component packages and install special property editors. I've spent the last week or so looking at examples and tutorials, I must clearly be doing something wrong because my property editors never show up in the Object Inspector and I require step by step instructions to try and resolve this frustration.

Component package

I currently have one package and it is set in designtime and runtime

in options. Added modules to this package for my components (e.g. MyButton, MyListBox, etc.). Also, I have a unit containing a procedure RegisterComponents

. I can build and install this now, add my components to a new project and run them without any problem.

Adding a custom PropertyEditor

It becomes more complicated and confusing for me that I want to present a property editor to my components from the above package.

TMyButton, for example, is a custom button with my own drawing methods, it has already published properties to change the appearance of the button. In addition, there is also a published list allowing you to choose from preset appearance options, for example:

TMyButtonStyle = (bsStyle1, bsStyle2, bsStyle3)

I want to pick up a list of preset styles and instead add a property to the Object Inspector named "PresetStyles". This property will be paDialog, I want to show a form where I can visually see different button styles - a more graphical way to select a preset style and then from a simple list.

What packages do I need

If I understand you need to separate packages designtime

and runtime

packages?

Does this mean that I need two registration blocks, one for components and one for property editors?

I'm not sure how to do this as I said my current package is designtime and runtime

, I'm not sure what type of package I should split into it. If I create a new design package for the property editors and make a different package runtime

, I only lose the install button. Even writing it now confuses me.

Installing PropertyEditor

One of the articles I tried was given on this page: http://www.delphisources.ru/pages/faq/master-delphi-7/content/LiB0097.html

The only thing I changed was to add my own dialog form and change the register code with:

RegisterPropertyEditor(TypeInfo(string), TMdSoundButton, 'SoundUp', TSoundProperty);

to

RegisterPropertyEditor(TypeInfo(string), TMyButton, 'PresetStyles', TSoundProperty);

I know it still says TSoundProperty, I just left it like this until I could get it to work, then I would change the class name.

Conclusion

What is the correct way to split / manage packages between the actual components and the project side i.e. PropertyEditors?

The PropertyEditor never appears in the TMyButton in the Object Inspector, and I have a feeling it must be due to misconfiguration of packages or something.

I would really love some help here, even a link to a really good tutorial on the tutorial or something like that I am not doing anything seems to work, even if using many examples does not work for me.

+3


source to share


3 answers


I currently have one package and it is configured at design time and run time in options.

To implement custom property / component editors, you MUST separate your code into two packages - one runtime only

package that contains only the implementation code for the components themselves, and one package designtime only

that contains only the implementation code for registering the components and custom editors. The designtime package must list the runtime package and package designide

in its list Requires

. The runtime is what is compiled into executables. The designtime package is what the IDE uses to make your components appear and interact with the Component Palette and Form Designer.

Does this mean that I need two registration blocks, one for components and one for property editors?

Not. There should be no registrations in the runtime package. Instead, it refers to the designtime package. You can have one function Register()

in the designtime package that registers everything.

If I create a new design package for Property Editors and only do the runtime of another package, I lose the install button.

You cannot install a runtime package in the IDE, only a design time package.



One of the articles I tried was one from this page: http://www.delphisources.ru/pages/faq/master-delphi-7/content/LiB0097.html

The only thing I changed was to add my own dialog form and change the register code with:

RegisterPropertyEditor (TypeInfo (string), TMdSoundButton, 'SoundUp', TSoundProperty);

to

RegisterPropertyEditor (TypeInfo (string), TMyButton, 'PresetStyles', TSoundProperty);

Does your component actually TMyButton

define a property PresetStyles

that is a type String

? You cannot define a property editor for a property that does not exist.

Without knowing exactly how your property is PresetStyles

implemented in the component itself and what it represents, it probably doesn't make sense to invoke a popup dialog for the property String

(except perhaps for things like filenames, etc.). Based on your description, it probably makes sense to inject a component editor instead of a property editor and leave only the existing propertyTMyButtonStyle

to use the IDE's standard editor for enumeration properties. To bring up the pop-up dialog box, the component editor will allow the user to right-click the component itself and select Edit (or whatever string value you choose to name) from the pop-up menu, or simply double-click the component icon in the form designer. Then you can display and edit the component as desired and assign any changes to the component when the dialog is closed.

The PropertyEditor never appears in the TMyButton in the Object Inspector, and I have a feeling it must be due to misconfiguration of packages or something.

It's hard to know for sure since you haven't shown your actual code yet.

+7


source


If I understand you need to separate development-time packages and run-time packages?

Does this mean that I need two registration blocks, one for components and one for property editors?



Not. A single registration unit that registers both components and property editors is sufficient if that registration block is not used at runtime (which it usually is not). This also applies to the block containing the property editor. Prevent use DesignEditors.pas

at runtime and then you're good to go.

+5


source


Component package

It's good that we have one package for both today. In the past, it made sense to separate them if the application was distributed with runtime packages to reduce the overall size. I like to separate them into separate implementation and design interface.

What packages do I need

If you have two packages, the runtime packages must be listed in the Required section of the design-time package. Therefore, you only need to register the design-time package. The runtime package is implicitly loaded into the IDE. In your case with one package, you need to register this.

Installing PropertyEditor

There is something wrong with the first parameter. This must be the info type of the property.

RegisterPropertyEditor(TypeInfo(TMyButtonStyle), TMdSoundButton, 'PresetStyles', TSoundProperty);

      

TSoundProperty must be descand of TEnumProperty.

Conclusion

Keep working with one package. The property should appear with the modified code. Unless you check that the property is not read-only.

+2


source







All Articles