Yes - thanks all for helping me with this. Because there is now Delphi equivalent there was no 'bell' to be rung but I understand now.

--------------------------------------------------
From: "Sid Gudes" <[email protected]>
Sent: Tuesday, September 01, 2009 3:40 PM
To: "Delphi-Talk Discussion List" <[email protected]>
Subject: Re: Variant Records

These refer to C bit fields. There is no equivalent structure in Delphi, you would have to use the Delphi AND and SHR operators to get the equivalent functionality. This is probably what you'd need to do to read the two bit fields (OTTOMH); writing to Recipient and DataDirection are exercises left to the reader. :-)

type
  TbmRequestType = object
      bits: byte;
      function Recipient: integer;
      function DataDirection: integer;
   end;

function TbmRequestType.Recipient: integer;
begin
   result := (bits shr 3) and $1F;
end;

function TbmRequestType.DataDirection: integer;
begin
   result := (bits shr 2) and $01;
end;

This is because the C bit-level declaration lays out the byte named "Bits" as this (where X represents a bit):

   Recipient    DataDirection   Unused
     XXXXX      X               XX

So total of 8 bits. (IIRC, the bits are laid out high-order to low-order, but maybe I'm remembering that incorrectly, so please double check.)


At 02:46 PM 9/1/2009, James Brown wrote:
I cannot figure out what the equivalent Delphi for this C struct would be:
typedef struct _USB_DEVICE_REQUEST {
   union
   {
       BYTE  bmRequestType;
       struct
       {
           BYTE Recipient:5;
           BYTE DataDirection:1;
      }
       Bits;
};
I know it's a type of free union variant but what the heck is it.

Thanks........ Jim
__________________________________________________
Delphi-Talk mailing list -> [email protected]
http://lists.elists.org/cgi-bin/mailman/listinfo/delphi-talk

Regards,
Sid Gudes
PIA Systems Corporation
[email protected]

__________________________________________________
Delphi-Talk mailing list -> [email protected]
http://lists.elists.org/cgi-bin/mailman/listinfo/delphi-talk

__________________________________________________
Delphi-Talk mailing list -> [email protected]
http://lists.elists.org/cgi-bin/mailman/listinfo/delphi-talk

Reply via email to