Board index » cppbuilder » Enum Lists

Enum Lists


2007-12-05 04:54:37 AM
cppbuilder111
not sure if i'm in the right place here. basically, i'm looking for a
way to get a list of enum names. for example, the property editor for
TPanel will have a drop down list of enum values by name (alLeft,
alCenter, etc) for Align.
can i get that list, perhaps as a TStringList, for use in my own program?
 
 

Re:Enum Lists

"Kirt" < XXXX@XXXXX.COM >wrote in message
Quote
i'm looking for a way to get a list of enum names.
Look at the GetEnumName() and GetEnumValue() functions in the TypInfo unit.
Quote
for example, the property editor for TPanel will have a drop down
list of enum values by name (alLeft, alCenter, etc) for Align.
The Object Inspector is using the RTTI of the property to generate that
list. It knows the starting and ending values for the TAlign enum (or any
other enum-based property) and simply runs a loop, passing each numeric
value in between to GetEnumName().
Quote
can i get that list, perhaps as a TStringList, for use in my own program?
Only if you have an enum from a published property that has RTTI attached to
it. If you want to generate such a list for a standalone enum, then you
have to put it into a wrapper class, since enums by themselves don't have
any RTTI in C++. For example:
groups.google.com/group/borland.public.cppbuilder.vcl.components.using/msg/f03d3673a62c204c
Gambit
 

Re:Enum Lists

Remy Lebeau (TeamB) wrote:
Quote
>can i get that list, perhaps as a TStringList, for use in my own program?

Only if you have an enum from a published property that has RTTI attached to
it. If you want to generate such a list for a standalone enum, then you
have to put it into a wrapper class, since enums by themselves don't have
any RTTI in C++. For example:
gotcha. thanks.
 

{smallsort}

Re:Enum Lists

Remy Lebeau (TeamB) wrote:
I looked the code and 'd like to use it, but I can not get it to
compile! I just copied it form the link and it came with some funny
characters. Where can I get a clean copy to try it out?
Thanks
 

Re:Enum Lists

"Bill" < XXXX@XXXXX.COM >wrote in message
Quote
I looked the code and 'd like to use it, but I can not get
it to compile!
Then you did not copy it into your project correctly. I've used that code
in several projects, so I know it works in general.
Quote
I just copied it form the link and it came with some funny characters.
Then your web browser did not display it correctly.
Gambit
 

Re:Enum Lists

Hi Remy
Remy Lebeau (TeamB) says:
Quote

"Bill" < XXXX@XXXXX.COM >wrote in message
news:47698736$ XXXX@XXXXX.COM ...

>I looked the code and 'd like to use it, but I can not get
>it to compile!

Then you did not copy it into your project correctly. I've used that code
in several projects, so I know it works in general.

>I just copied it form the link and it came with some funny characters.

Then your web browser did not display it correctly.
Mine doesn't either, I also get al kind of strange
characters in that special post, not the others in
the thread though.
Just thought You should know.
Kind regards
Asger
 

Re:Enum Lists

"Asger Joergensen" < XXXX@XXXXX.COM >wrote in message
Quote
Mine doesn't either, I also get al kind of strange characters in that
special post
Such as? Please be more specific. It shows up fine when I look at it.
Gambit
 

Re:Enum Lists

Hi Remy Lebeau (TeamB)
Remy Lebeau (TeamB) says:
Quote

"Asger Joergensen" < XXXX@XXXXX.COM >wrote in message
news: XXXX@XXXXX.COM ...

>Mine doesn't either, I also get al kind of strange characters in that
>special post

Such as? Please be more specific. It shows up fine when I look at it.
#define DECLARE_ENUM_TYPEINFO(e) \
\
class e##_HACKED_ENUM_TYPEINFO : public TObject \
{ \
private: \
e FTestEnum; \
__published: \
__property e eProp = \
 

Re:Enum Lists

"Asger Joergensen" < XXXX@XXXXX.COM >wrote in message
Quote
#define DECLARE_ENUM_TYPEINFO(e) \
<snip>
And the problem is? That is how it is supposed to look.
Gambit
 

Re:Enum Lists

"Remy Lebeau (TeamB)" < XXXX@XXXXX.COM >wrote in message
Quote
That is how it is supposed to look.
Look closely at what the code is actually doing. It is using a #define
macro to create a class wrapper for a specified enum type. The '\' and '##'
tokens have special meaning inside a #define statement.
Gambit
 

Re:Enum Lists

Hi Remy
Remy Lebeau (TeamB) says:
Quote

"Remy Lebeau (TeamB)" < XXXX@XXXXX.COM >wrote in message
news:476a001f$ XXXX@XXXXX.COM ...

>That is how it is supposed to look.

Look closely at what the code is actually doing. It is using a #define
macro to create a class wrapper for a specified enum type. The '\' and '##'
tokens have special meaning inside a #define statement.
LOL. Very sory.
I just never seen anything like it.
Kind regards
Asger
 

Re:Enum Lists

Remy Lebeau (TeamB) wrote:
Quote
"Remy Lebeau (TeamB)" < XXXX@XXXXX.COM >wrote in message
news:476a001f$ XXXX@XXXXX.COM ...

>That is how it is supposed to look.

Look closely at what the code is actually doing. It is using a #define
macro to create a class wrapper for a specified enum type. The '\' and '##'
tokens have special meaning inside a #define statement.


Gambit


Thanks. It does work! I didn't understand the code!
The only error I get is at
if(EditFlags.Contains((TExtEditFlag)x))
TreeView2->Items->Add(NULL, GetEnumName(pTypeInfo, x));
The compiler complains EditFlags.Contains :
[BCC32 Error] Unit1.cpp(95): E2294 Structure required on left side of .
or .*
Thanks
 

Re:Enum Lists

"Bill" < XXXX@XXXXX.COM >wrote in message
Quote
The only error I get is at
<snip>
That portion of the code was just an example of how to use the macro and
RTTI. It was copied from a design-time editor for one of my components.
TExtEditFlag is an enum, and EditFlags is a Set of TExtEditFlag values:
typedef Set<TExtEditFlag, firstvalue, lastvalue>TExtEditFlags;
Use whatever enums you want. The Set is optional. You could just display
all of the enum values in the loop, ie:
DECLARE_ENUM_TYPEINFO(TSomeEnum);
PTypeInfo pTypeInfo = GET_ENUM_TYPEINFO(TSomeEnum);
PTypeData pTypeData = GET_ENUM_TYPEDATA(TSomeEnum);
for(int x = pTypeData->MinValue; x <= pTypeData->MaxValue; ++x)
ShowMessage(GetEnumName(pTypeInfo, x));
Gambit
 

Re:Enum Lists

Remy Lebeau (TeamB) wrote:
Quote
"Bill" < XXXX@XXXXX.COM >wrote in message
news: XXXX@XXXXX.COM ...

>The only error I get is at
<snip>

That portion of the code was just an example of how to use the macro and
RTTI. It was copied from a design-time editor for one of my components.
TExtEditFlag is an enum, and EditFlags is a Set of TExtEditFlag values:


Gambit


Thanks. I've implemented the code in my project and it is working vary well.
I remember asking for some thing similar to this a few years back and
was told to use std::map. This helps a lot!
Thanks again