How do I register the property editor "TJvDefaultImageIndexProperty" in C++ Builder?

64 views Asked by At

I have an ImageIndex property of the type TImageIndex. I need to register the property editor TJvDefaultImageIndexProperty to get a nice list of images to select from in the object inspector.

The only example I can find is for Delphi.

RegisterPropertyEditor(TypeInfo(TImageIndex), TMyComponent, 'ImageIndex', TJvDefaultImageIndexProperty);

Translated to C++ Builder I guess it would be something like.

RegisterPropertyEditor(__typeinfo(TImageIndex), __classid(TMyComponent), L"ImageIndex", __classid(TJvDefaultImageIndexProperty));

When I compile it complains System::Uitypes::TImageIndex (aka 'int') is not a class, namespace, or enumeration. __typeinfo() is only a macro so it expands to (PTypeInfo)TImageIndex::ClassInfo() or more accurately (PTypeInfo)int::ClassInfo() since TImageIndex is just a typedef of int. Obviously int isn't a class with a member ClassInfo(), so it will not work.

So, how can register a property editor that allows me to select from a list of images?

1

There are 1 answers

0
Remy Lebeau On

As you have discovered, __typeinfo only works for classes, not fundamental types.

The best way to get the necessary PTypeInfo pointer for a property's type, regardless of the actual type used, is to just ask the property's RTTI for the PTypeInfo, eg:

PPropInfo PropInfo = GetPropInfo(__typeinfo(TMyComponent), L"ImageIndex");
RegisterPropertyEditor(*(PropInfo->PropType), __classid(TMyComponent), L"ImageIndex", __classid(TJvDefaultImageIndexProperty));