Registering editors for properties of not-VCL types

 

To associate a custom property editor with the property type of a component´s class the RegisterPropertyEditor function is used:

extern PACKAGE void __fastcall RegisterPropertyEditor
	(Typinfo::PtypeInfo PropertyType, System::TMetaClass* ComponentClass, 
	const AnsiString PropertyName, System::TMetaClass* EditorClass);

Specifying the ComponentClass, PropertyName, EditorClass parameters of this function does not represent any problems. In the C++ Builder help to determine the PropertyType parameter, it is offered to use the __typeinfo macro defined by the following way:

#define __typeinfo(type) (PTypeInfo)TObject::ClassInfo(__classid(type))

From definition of this macro follows, that it can be applied only to classes which are descendants of TObject. Therefore, custom editors for properties of another types can´t be registered by this way.

To solve this problem it is necessary to find another way to get the type information pointers for properties of types which are not descendants of TObject. For this purpose the GetPropInfo function can be used. It is defined in the "typinfo.hpp" file as:

extern PACKAGE PPropInfo __fastcall GetPropInfo(PTypeInfo TypeInfo,
	const AnsiString PropName);

This function returns the pointer to the property information record for the property specified by the PropName parameter. The component´s class is determined by the TypeInfo parameter. The property information record contains the PropType pointer to the type information pointer. Therefore, to get the type information pointer for property of the component´s class (the PropertyType parameter for call of RegisterPropertyEditor) the following construction can be used:

Typinfo::PTypeInfo PropertyType = *GetPropInfo((Typinfo::TTypeInfo*)
	TObject::ClassInfo(ComponentClass), PropertyName)->PropType;

For this purpose the macro can be used. It is defined as follows:

#define proptypeinfo(ComponentClass, PropertyName)
	(*GetPropInfo((Typinfo::TTypeInfo*) TObject::ClassInfo(ComponentClass),
	PropertyName)->PropType)

The source code can be simplified if to register the custom property editor by the following function:

void __fastcall RegisterPropertyEditorEx (System::TMetaClass* ComponentClass,
	const AnsiString PropertyName, System::TMetaClass* EditorClass)
{
	RegisterPropertyEditor(proptypeinfo (ComponentClass, PropertyName),
		ComponentClass, PropertyName, EditorClass);
}

Nikolay Antonov & Vyatcheslav Baranov. MBLab, 9/20/2001.

 
Home  -   Company  -   Sources  -   Products  -   Download  -   Order  -   Support  -   Forums  -   Contact
Copyright © 2001-2004 MBLabSoft. All Rights Reserved.