Reputation: 455
I would like to know how to convert C struct to Delphi record?
The following code is in C. I want to convert to Delphi.
typedef struct
{
Uint16 value1[32];
Uint16 value2[22];
Uint16 value3[8];
}MY_STRUCT_1;
Thanks in advance.
Upvotes: 5
Views: 5282
Reputation:
You might need to used the packed keyword. Delphi, by default, will align variables based on (I believe) whether you're developing on a 16, 32 or 64 bit platform and what data types are within your record. Using packed will change the length/size of memory required to hold the record. C will pack the structure by default.
MY_STRUCT_1 = packed record
value1 : Array [0..31] of Word;
value2 : Array [0..21] of Word;
value3 : Array [0..7] of Word;
end;
See also: http://www.delphibasics.co.uk/RTL.asp?Name=Packed
Upvotes: 3
Reputation: 136441
The Uint16 is equivalent to the Word type and the []
indicates an array.
MY_STRUCT_1 = record
value1 : Array [0..31] of Word;
value2 : Array [0..21] of Word;
value3 : Array [0..7] of Word;
end;
Upvotes: 11