Due to the essential difference between PASCAL and C , in the strong RTTI function in Delphi, it is relatively weakened in the BCB. In this way, BCB can still enjoy the benefits of TOBJECT, although we cannot use GetenumName in Delphi.
We still don't need to implement a static string list for each enumerated type.
Consider the following macro implementation, in order to enjoy the benefits of TOBJECT, we need to inherit a VCL subclass from it.
And declare an attribute for this class, so that we can use GetPropInfo to get Enum type information.
#include
#define marco_prepareenumenderAme (Enum) /
Class ___tenumObject___: Tobject /
{/
ENUM _SE; /
__published: /
__property enum prop = {read = _se}; /
}; /
Ansistring GeTenumName (Const Enum & Value) /
{/
/
Ppropinfo Apropinfo = getPropInfo (__ typeinfo (___temobject___), "prop"); /
IF (APROPINFO) /
{/
Return genumname (* (Apropinfo-> PropType), int (value)); /
} /
Return ""; /
}
With this macro, it makes it easier when you get the enum type in the future.
Originally plans to use Template technology to implement, but the template parameters are not allowed after __property declaration. So
// The following is the test code
Typedef enum {xxx, yyy, zzz, eee, fff} tsampleenum
Marco_prepareenumender (TsampleEnum)
Void __fastcall tform1 :: button1click (Tobject * Sender)
{
Caption = getenumname (xxx);
}