Transferring a C structure to a Delphi record

I would like to know how to convert a C structure to a 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.

+4
source share
2 answers

Uint16 is equivalent to the type of Word, and [] 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; 
+11
source

You may need a packed keyword. By default, Delphi will align the variables based on (I believe) whether you are developing on a 16, 32 or 64 bit platform and what data types are in your record. Using packed will change the length / size of the memory needed to store 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

+2
source

Source: https://habr.com/ru/post/1393295/


All Articles