Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to translate C/C++ "Union" to Delphi?

332 views
Skip to first unread message

Pascal Enz

unread,
Apr 26, 1998, 3:00:00 AM4/26/98
to

How can I translate the word union from C/C++ to Pascal (Delphi 3.0)?
(see the following example!)

typedef struct

DWORD cbStruct;
union

DWORD dwControlID;
DWORD dwControlType;
};
DWORD cControls;
} MyType

pasca...@bluewin.ch

Earl F. Glynn

unread,
Apr 26, 1998, 3:00:00 AM4/26/98
to

Pascal Enz wrote in message <6hvcp2$bfu$1...@bw107zhb.bluewin.ch>...


Pascal

You need a variant record to get the equivalent of a
C union. Something like this:

VAR
Overlay:
RECORD
CASE INTEGER OF
0: (dwControlID: INTEGER);
1: (dwControlType: INTEGER)
END; // Only one "End" here

If you only have a single integer value overlaying another
integer value, you might want to use the ABSOLUTE
keyword:

VAR
dwControlID: INTEGER;
dwControlType: INTEGER ABSOLUTE dwControlID;

efg
_________________________________________
efg's Computer Lab: http://infomaster.net/external/efg

Earl F. Glynn E-Mail: Earl...@att.net
MedTech Research Corporation, Lenexa, KS USA


Boris Podchezertseff

unread,
Apr 27, 1998, 3:00:00 AM4/27/98
to Pascal Enz

Pascal Enz wrote:
>
> How can I translate the word union from C/C++ to Pascal (Delphi 3.0)?
> (see the following example!)
>
> typedef struct
>
> DWORD cbStruct;
> union
>
> DWORD dwControlID;
> DWORD dwControlType;
> };
> DWORD cControls;
> } MyType

All fields after UNION section must be moved into UNION.

use this:
type
MyType = record
cbStruct: LongInt;
case Integer of
1: ( dwControlID: LongInt;
cControls : LongInt
);
2: ( dwControlType: LongInt
)
end;

or this:

type
MyType = record
case cbStruct: LongInt of
sControlID: (
dwControlID: LongInt;
cControls : LongInt
);
sControlType: (
dwControlType: LongInt
)
end;


Mark Hack

unread,
Apr 29, 1998, 3:00:00 AM4/29/98
to

I've always wondered about this. How does the case statement in this type of
construct work?

Mark...

Boris Podchezertseff wrote in message <354416FE...@finros.ru>...

> dwControlID: LongInt;
> cControls : LongInt
> );
> sControlType:

> dwControlType: LongInt
> )
> end;
>

0 new messages