How to associate Imagelist property with ImageIndex property in Objectinspector at design time?
surely you know the easy manipulation in object inspector at design time with ImageList and ImageIndex properties. After assigning Imagelist you can click on ImageIndex property, and nice list of images togeather with their indexes appears. I am trying to make my own control, which has imagelist and imageindex properties. But I wonder, how can I let object inspector "know" (or make it aware), that my defined imageindex property should be picked up from combobox. (which is built in object inspector 开发者_StackOverflow社区itself) Does anybody know the trick?
thanx very much
I have never tried to do this, but I would suspect that this will work:
In your component, declare the ImageIndex
property not as integer
, but as TImageIndex
.
That is, write (for instance)
private
FImageIndex: TImageIndex;
published
property ImageIndex: TImageIndex read FImageIndex write SetImageIndex default -1;
instead of
private
FImageIndex: integer;
published
property ImageIndex: integer read FImageIndex write SetImageIndex default -1;
TImageIndex
is defined as
type
TImageIndex = type Integer;
so it is really an integer, but a different type.
(As a footnote, if the definition had been
type
TImageIndex = Integer;
then TImageIndex
would have been just another name of Integer
, and so noone (not even the IDE) would have been able to distinguish TImageIndex
from Integer
. Now they are two different types, but, of course, assignment-compatible ones.)
It is a little bit more complicated than Andreas suggested. You can study the way the Jedi VCL handles this. Search for TJvDefaultImageIndexProperty in the Design folder as a start.
To allow the Object Inspector to be aware of, you have to register a Property Editor in your design package.
If you're using jvcl take a look at the TJvDefaultImageIndexProperty class defined in the jvcl\design\JvDsgnEditors.
After you have it, to in your register procedure call RegisterPropertyEditor like this:
begin
RegisterPropertyEditor(TypeInfo(TImageIndex), TMyComponent, 'ImageIndex',TJvDefaultImageIndexProperty);
end;
For clarification, take a look at the jvcl\design\JvStdCtrlsReg.pas or google for Delphi OTA examples.
精彩评论