[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 477
  • Last Modified:

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
);

?

0
Palamedes
Asked:
Palamedes
  • 6
  • 4
1 Solution
 
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

  • 6
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now