What is the Delphi equivalent of an ENUM like this?

What is the Delphi equivalent of this;

enum ExternalEventID
      {      // Valid fields: >>>>>>>>>>>>>      
      EVID_CHAT_MESSAGE,      
      EVID_PLAYER_LOGGED_ON,      
      EVID_PLAYER_LOGGED_OFF,      
      EVID_MAJOR_EVENT,      
      EVID_PLAYER_NAME,
      EVID_ISLAND_NAME,
      EVID_OBJECT_NAME,
      EVID_OBJECT_TYPE,
            NUM_EXTERNAL_EVENTS
      };

Is this just a set?

So;

type ExternalEventID = set of (      EVID_CHAT_MESSAGE,      
      EVID_PLAYER_LOGGED_ON,      
      EVID_PLAYER_LOGGED_OFF,      
      EVID_MAJOR_EVENT,      
      EVID_PLAYER_NAME,
      EVID_ISLAND_NAME,
      EVID_OBJECT_NAME,
      EVID_OBJECT_TYPE,
      NUM_EXTERNAL_EVENTS
);

?

LVL 4
PalamedesAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

PalamedesAuthor Commented:
OR, should it be more like this;

  type ExternalEventID = record
    EVID_CHAT_MESSAGE       : integer;
    EVID_PLAYER_LOGGED_ON   : integer;
    EVID_PLAYER_LOGGED_OFF  : integer;
    EVID_MAJOR_EVENT        : integer;
    EVID_PLAYER_NAME        : integer;
    EVID_ISLAND_NAME        : integer;
    EVID_OBJECT_NAME        : integer;
    EVID_OBJECT_TYPE        : integer;
    NUM_EXTERNAL_EVENTS     : integer;
    end;
0
PalamedesAuthor Commented:
Or is it just this;

  type ExternalEventID = (
    EVID_CHAT_MESSAGE,
    EVID_PLAYER_LOGGED_ON,
    EVID_PLAYER_LOGGED_OFF,
    EVID_MAJOR_EVENT,
    EVID_PLAYER_NAME,
    EVID_ISLAND_NAME,
    EVID_OBJECT_NAME,
    EVID_OBJECT_TYPE,
    NUM_EXTERNAL_EVENTS
    );
0
Russell LibbySoftware Engineer, Advisory Commented:
The equivalent is a set. But C enums are a little different in the fact that

1.) They dont need to start with zero, like a Delphi set would. If there is no
xxx = num,
in the first element, then the first element will start with zero.

2.) They don't have to be 1 byte in size, and its most common (in C) to define them as 4 bytes. This corresponds to the $Z4 directive in delphi.

Most likely what you are after is:

{$Z4}

 type ExternalEventID = (
    EVID_CHAT_MESSAGE,
    EVID_PLAYER_LOGGED_ON,
    EVID_PLAYER_LOGGED_OFF,
    EVID_MAJOR_EVENT,
    EVID_PLAYER_NAME,
    EVID_ISLAND_NAME,
    EVID_OBJECT_NAME,
    EVID_OBJECT_TYPE,
    NUM_EXTERNAL_EVENTS
    );


Regards,
Russell

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

PalamedesAuthor Commented:
Excellent.. that worked..
0
Russell LibbySoftware Engineer, Advisory Commented:
No problem, anytime ;-)

Russell
0
PalamedesAuthor Commented:
I sure do appreciate smart people.. we need more of you..
0
PalamedesAuthor Commented:
Hey Russell,

What does this mean;

Enums are 4 byte aligned. Some of the recent ones for the next release are 4 bytes aligned and 4 bytes wide (you'll see the FORCE_DWORD enumerator entry set to 0xffffffff)

This was the response I got when I asked..  

0
Russell LibbySoftware Engineer, Advisory Commented:
All it means is that you need to use the {$Z4}, which will force delphi to use integer size for set storage.

$Z4 = Integer (4 bytes)
$Z2 = Word (2 bytes)
$Z1 = Byte (1 byte)

If no $ZNUMBER setting is specified, Delphi will use the smallest data size needed for the set. For example, a set with less than 256 elements would fit in a byte, and thus be 1 byte aligned. In order to operate with other languages, Delphi allows us to specifically set the storage size. (which is what you need to/have already done here)

-----

Russell

0
PalamedesAuthor Commented:
AH I see.. okay.. I wasnt sure if "4 bytes aligned and 4 bytes wide" meant something different than what you had previously said.. Awesome.. thanks man.. (And you're fast!  Don't you ever sleep!  hehe)

0
Russell LibbySoftware Engineer, Advisory Commented:
The alignment DOES mean something different, but you don't have any contol over it

<delphi help>
Regardless of the state of the $A directive, variables and typed constants are always aligned for optimal access. In the {$A+} state, execution will be faster.
<>

But if your using $Z4, you will get both 4 byte size AND 4 byte alignment on the data (so no need for concern).

Glad I could help (and I do sleep..... sometimes <g>)

Russell
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.