[英]How do I register the property editor "TJvDefaultImageIndexProperty" in C++ Builder?
I have an ImageIndex
property of the type TImageIndex
.我有一个
TImageIndex
类型的ImageIndex
属性。 I need to register the property editor TJvDefaultImageIndexProperty
to get a nice list of images to select from in the object inspector.我需要注册属性编辑器
TJvDefaultImageIndexProperty
以获得一个不错的图像列表,以便在对象检查器中进行选择。
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.翻译成 C++ Builder 我想它会是这样的。
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
.当我编译它抱怨
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
. __typeinfo()
只是一个宏,因此它扩展为(PTypeInfo)TImageIndex::ClassInfo()
或更准确地说是(PTypeInfo)int::ClassInfo()
因为TImageIndex
只是int
的 typedef。 Obviously int
isn't a class with a member ClassInfo()
, so it will not work.显然
int
不是具有成员ClassInfo()
的类,因此它不起作用。
So, how can register a property editor that allows me to select from a list of images?那么,如何注册一个允许我从图像列表中进行选择的属性编辑器呢?
As you have discovered, __typeinfo
only works for classes, not fundamental types.正如您所发现的,
__typeinfo
仅适用于类,而不适用于基本类型。
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:无论使用的实际类型如何,获取属性类型所需的
PTypeInfo
指针的最佳方法是仅向属性的 RTTI 询问PTypeInfo
,例如:
PPropInfo PropInfo = GetPropInfo(__typeinfo(TMyComponent), L"ImageIndex");
RegisterPropertyEditor(*(PropInfo->PropType), __classid(TMyComponent), L"ImageIndex", __classid(TJvDefaultImageIndexProperty));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.