tags:

views:

93

answers:

3

Hi,

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 itself) Does anybody know the trick?

thanx very much

+3  A: 

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.)

Andreas Rejbrand
No, that does not work... The problem is (what I see), that you must somewhere declare, that this ImageIndex belongs to that Imagelist. Imagine you have 3 ImageLists and 3 imageindexes. How object inspector "knows" which belongs to what?
lyborko
@Iyborko: It might be that *too*, yes.
Andreas Rejbrand
I tried it now... In fact one thing is changed: instead of the edit box, by which you can edit integer values, combobox arrow appeared when I tried edit imageindex value. I appreciate your answers very much and I say sorry, if my No might sounded a little bit arrogant...
lyborko
@Lyborko, you're off to a good start. The first step is indeed to use `TImageIndex` as the property type. The next step is to figure out how to associate a `TImageList` with the component you're editing, which itself probably doesn't have an `ImageList` or `Images` property. Its *owner* or *container* might, though.
Rob Kennedy
A: 

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.

Uwe Raabe
A: 

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.

jachguate