You must write your own property editor for this specific property. Read unit
PropEdits in folder components/ideintf of your Lazarus installation. There is a long comment beginning with "{TPropertyEditor" which explains a lot of the mysterious methods and properties...
Assuming that the property of your custom component for which you want to add icons to the object inspector is an enumeration. Then the TAChart sample is exactly what you are looking for. Let me explain it for the "TSeriesPointerStyle" enumeration in TAChart - this is an enumeration, and you should inherit the new property editor ("TSeriesPointerStylePropertyEditor") from "TEnumPropertyEditor". This way you already get the feature that a dropdown with all the enumeration elements opens when the user wants to edit this property.
You find this code in folder components/tachart/editors/taseriespropeditors.
All you have to do is to custom-draw the combobox items:
- In order to activate custom-drawing you must override the method GetAttributes and add the paCustomDrawn option. The options already inherited from TEnumPropertyEditor are [paMultiSelect, paValueList, paSortList, paRevertable] - the important one is paValueList which is responsible to create the combobox. paSortList sorts the enumeration items in the combobox alphabetically. See unit PropEdits for an explanation of the others.
- ListDrawValue is called by the property editor to draw the combobox items. It is very similar to the custom-draw event of a combobox. "ARect" is the rectangle in which the item will be drawn. In the inherited property editor the text begins immediately at the left side, but now you need to provide space for the icon. Therefore "ARect" is split into two parts: a rectangle "lRect" (a square defined by the rectangle height) for the icon, and the rest of ARect for the text (which is drawn by the inherited procedure). "AValue" is the string currently to be displayed, in the seriespointer example, e.g. "psRectangle". Use the standard function GetEnumValue (in unit TypInfo) to extract the index of this name in the enumeration. Now how have all information needed to draw the pointer icon (new "DrawPointer" method implemented for the property editor).
- I cannot remember whether it is really needed to override the methods "ListMeasureWidth" and "PropDrawValue"; i commented them out and the editor is still working...
- One important step is still missing: the registration of the property editor. In the registration unit of your package (i.e. where you call RegisterComponents), method Register, call RegisterPropertyEditor with the following parameters
- Type info of the property ("TypeInfo(TSeriesPointerStyle)")
- Type which will use this property editor ("TSeriesPointer")
- Name of the property which will use this property. If you leave it empty it will work for all properties of type specified above.
- Name of the property editor class to be used
- When using dedicated property and component editors it is highly recommended to create a dedicated designtime package for the registered components and editors. Otherwise all this code which is needed only by the IDE would be linked to your appliction. (But this is not absolutely necessary. If you prefer a single package it must be runtime/designtime package, however)
- Rebuild the IDE. Be prepared for crashes during the development phase!