title: How to simulate bit-fields in Delphi records?
body: <p>I would like to declare a record in Delphi that contains the same layout as it has in C.</p>
  
  <p>For those interested : This record is part of a union in the Windows OS's LDT_ENTRY record. (I need to use this record in Delphi because I'm working on an Xbox emulator in Delphi - see project Dxbx on sourceforge).</p>
  
  <p>Anyway, the record in question is defined as:</p>
  
  <pre><code>    struct
      {
          DWORD   BaseMid : 8;
          DWORD   Type : 5;
          DWORD   Dpl : 2;
          DWORD   Pres : 1;
          DWORD   LimitHi : 4;
          DWORD   Sys : 1;
          DWORD   Reserved_0 : 1;
          DWORD   Default_Big : 1;
          DWORD   Granularity : 1;
          DWORD   BaseHi : 8;
      }
      Bits;
  </code></pre>
  
  <p>As far as I know, there are no bit-fields possible in Delphi. I did try this:</p>
  
  <pre><code> Bits = record
        BaseMid: Byte; // 8 bits
        _Type: 0..31; // 5 bits
        Dpl: 0..3; // 2 bits
        Pres: Boolean; // 1 bit
        LimitHi: 0..15; // 4 bits
        Sys: Boolean; // 1 bit
        Reserved_0: Boolean; // 1 bit
        Default_Big: Boolean; // 1 bit
        Granularity: Boolean; // 1 bit
        BaseHi: Byte; // 8 bits
    end;
  </code></pre>
  
  <p>But alas: it's size becomes 10 bytes, instead of the expected 4.
  I would like to know how I should declare the record, so that I get a record with the same layout, the same size, and the same members. Preferrably without loads of getter/setters.</p>
  
  <p>TIA.</p>