thanks to Rudy's Delphi Corner article on C++ -> Delphi conversion I've managed to convert more or less complex structures.
I'd like to ask this community if what I did is correct. Furthermore, I have some doubts to unravel.
This is what I did:
From C++ code:
typedef struct CorrId_t_ { unsigned int size:8; unsigned int valueType:4; unsigned int classId:16; unsigned int reserved:4; unsigned long long intValue; } CorrId_t; I did translate to the following code in Delphi (I wrote a few functions to access the bitfield):
interface type CorrId_t_ = record bitfield:Cardinal; //$000000FF=size; $00000F00=valueType; $0FFFF000=classId; $F0000000=reserved; intValue:Cardinal; //should be Uint64 but such integer type doesn't exist in Delphi 6 end; CorrId_t = CorrId_t_; PCorrId_t = ^CorrId_t; procedure CorrID_setSize(var rec:CorrId_t; value:byte); procedure CorrID_setValueType(var rec:CorrId_t; value:byte); procedure CorrID_setClassId(var rec:CorrId_t; value:Word); function CorrID_getSize(rec:CorrId_t):Byte; function CorrID_getValueType(rec:CorrId_t):Byte; function CorrID_getClassId(rec:CorrId_t):Word; implementation procedure CorrID_setSize(var rec:CorrId_t; Value:Byte); begin rec.bitfield := (rec.bitfield and $FFFFFF00) or Value; end; procedure CorrID_setValueType(var rec:CorrId_t; Value:Byte); begin rec.bitfield := (rec.bitfield and $FFFFF0FF) or Value; end; procedure CorrID_setClassId(var rec:CorrId_t; Value:Word); begin rec.bitfield := (rec.bitfield and $F0000FFF) or Value; end; function CorrID_getSize(rec:CorrId_t):Byte; begin Result := rec.bitfield and $000000FF; end; function CorrID_getValueType(rec:CorrId_t):Byte; begin Result := rec.bitfield and $00000F00; end; function CorrID_getClassId(rec:CorrId_t):Word; begin Result := rec.bitfield and $0FFFF000; end; Here are my questions for you:
1) are the bitwise operations (inside the set/get access functions) correct?
2) the "unsigned long long" integer type does not have any correspondence in Delphi 6. I can choose between Int64 (but it's signed) or a 32-bit unsigned integer type, such as Cardinal. Which is best in your opinion to use?
Thank you in advance!