Information
I seem absolutely clueless as to how I should manage my component packages and install custom property editors. I have spent the last week or so looking at examples and tutorials, I must clearly be doing something wrong as my property editors never show up in the Object Inspector and I require step by step instructions to try and solve this frustration.
Component Package
I currently have one package, and it is set to designtime and runtime in the options. Added to this package are the units to my components (ie, MyButton, MyListBox etc) – Additionally I have a unit containing the RegisterComponents procedure. I can build and install this now, add my components to a new project and run them without any problems.
Adding a custom PropertyEditor
It gets tricky and confusing for me now that I want to introduce a property editor to my components from the package above.
TMyButton for example is a custom button with my own paint methods, it already has published properties to allow changing the appearance of the button – In addition there is also a published list to allow selecting preset appearance settings, example:
TMyButtonStyle = (bsStyle1, bsStyle2, bsStyle3)
I want to take away the list of preset styles and instead add a property to the Object Inspector called ‘PresetStyles’. This property will be of paDialog, I want to a show a form where I can visually see the different button styles – a more graphical way of selecting a preset style then from a simple list.
Which packages do I need
If I understand, you need to split designtime packages and runtime packages?
Does this mean I need two register units, one for the components and one for the Property Editors?
I am not full sure how to manage this, as I said my current package is designtime and runtime, I am not sure what package type I should split it into. If I make a new designtime package for the Property Editors, and make the other package runtime only I lose the install button. Even writing this now is confusing me.
Installing the PropertyEditor
One of the articles I tried following was one from this page: http://www.delphisources.ru/pages/faq/master-delphi-7/content/LiB0097.html
The only thing I changed was add my own dialog form, and change the register code from:
RegisterPropertyEditor(TypeInfo(string), TMdSoundButton, 'SoundUp', TSoundProperty);
to
RegisterPropertyEditor(TypeInfo(string), TMyButton, 'PresetStyles', TSoundProperty);
I know it still says TSoundProperty, I just left it like that until I could get it working then I would change the class name.
Conclusion
What is the correct way of splitting/managing packages between actual components and the design side ie PropertyEditors?
The PropertyEditor never appears on TMyButton in the Object Inspector and I have a feeling it must be something to do with not configuring the packages correctly or something.
I would really appreciate some kind of assistance here, even a link to a really good tutorial guide or something as nothing I am doing seems to work, even using a lot of the examples are not working for me.
To implement custom property/component editors, you MUST separate your code into two packages – one
runtime onlypackage containing just the implementation code for the components themselves, and onedesigntime onlypackage that contains just the implementation code for the component registrations and custom editor(s). The designtime package needs to specify the runtime package, and thedesignidepackage, in itsRequireslist. The runtime package is what gets compiled into executables. The designtime package is what the IDE uses to get your components to appear in the Component Palette and Form Designer and interact with them.No. The runtime package should have no registrations at all. That belongs in the designtime package instead. You can have a single
Register()function in the designtime package that registers everything.You cannot install a runtime package into the IDE, only a designtime package.
Does your
TMyButtoncomponent actually define aPresetStylesproperty that is aStringtype? You cannot define a property editor for a property that does not exist.Without knowing exactly how your
PresetStylesproperty is implemented in the component itself and what it represents, it probably does not make much sense to invoke a popup Dialog for aStringproperty (except maybe for things like filenames and such). Based on your description, it probably makes more sense to implement a component editor instead of a property editor, and leave your existingTMyButtonStyleproperty alone to use the IDE’s default editor for enum properties. To invoke your popup dialog, the component editor would allow the user to right-click on the component itself and choose “Edit” (or whatever other string value you decide to name it) from the popup menu, or just double-click on the component, in the Form Designer. You can then display and edit the component as desired, and assign any changes to the component when the dialog is closed.It is hard to know for sure since you did not show any of your actual code yet.