Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5977391
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T21:21:49+00:00 2026-05-22T21:21:49+00:00

How is a set organized in memory in Delphi? What I try to do

  • 0

How is a set organized in memory in Delphi?

What I try to do is casting a simple type to a set type like

var
  MyNumber : Word;
  ShiftState : TShiftState;
begin
  MyNumber:=42;
  ShiftState:=TShiftState(MyNumber);
end;

Delphi (2009) won’t allow this and I don’t understand why. It would make my life a lot easier in cases where I get a number where single bits encode different enum values and I just could cast it like this. Can this be done?

One approach I was going to go for is:

var
  ShiftState : TShiftState;
  MyNumber : Word absolute ShiftState;
begin
  MyNumber:=42;
end;

But before doing this I thought I’d ask for the memory layout. It’s more a feeling than knowlege what I am having right now about this.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T21:21:50+00:00Added an answer on May 22, 2026 at 9:21 pm

    A Delphi set is a bit field who’s bits correspond to the associated values of the elements in your set. For a set of normal enumerated types the bit layout is straight-forward:

    • bit 0 corresponds to set element with ordinal value 0
    • bit 1 corresponds to set element with ordinal value 1
    • and so on.

    Things get a bit interesting when you’re dealing with a non-contiguous set or with a set that doesn’t start at 0. You can do that using Delphi’s subrange type (example: set of 3..7) or using enumerated types that specify the actual ordinal value for the elements:

    type enum=(seven=7, eight=8, eleven=11); 
    EnumSet = set of enum;
    

    In such cases Delphi will allocate the minimum required amount of bytes that will include all required bits, but will not “shift” bit values to use less space. In the EnumSet example Delphi will use two bytes:

    • The first byte will have it’s 7th bit associated with seven
    • The second byte will have bit 0 associated with eight
    • The second byte will have bit 3 associated with eleven

    You can see some tests I did over here: Delphi 2009 – Bug? Adding supposedly invalid values to a set

    Tests were done using Delphi 2010, didn’t repeat them for Delphi XE.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a data set that is organized in the following manner: Timestamp|A0001|A0002|A0003|A0004|B0001|B0002|B0003|B0004 ...
Set<Type> union = new HashSet<Type>(s1); union.addAll(s2); AND Set <Type> union = new HashSet<Type>(); union.addAll(s1);
Currently, I have a more or less organized set of projects I work or
I have an array with a series of event IDs organized like this: $event['year']['month']['day']
I have an HTML file (from Newegg) and their HTML is organized like below.
I have a first query that returns a set of entities: var resultSet =
For example, I have a large set of bulletins which are organized in a
I have data that is organized in panels like this (see below for output
I have a large set of data that I've collected that I'd like to
I have a set of data that's organized hierarchically that should be able to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.