3.6. Structure, Records
3.6.1. Simple Structure
C Structures Are Similar To Records in Delphi. Structures Are Usually Defined with The Typedef Keyword, But it's also Possible to do it with #define.
The Format of A Structure Declaration IS
{Struct | union} [Optidentifier] [Tagname] {FieldDefinitions [; ...]} [name "
You can ignore the tagname. It's used in c for subsequent References to the structure.
This Is How The Fields Withnin A Structure Are Defined:
#define RasentryNamea Struct TagrasentryNamea
RasentryNamea
{
DWORD DWSIZE;
CHAR SZENTRYNAME [RAS_MAXENTRYNAME 1];
}
This C declaration defines a record (structure) named RASENTRYNAMEA The Delphi-style name would be TRASENTRYNAMEA This structure contains two fields:.. The first is named dwSize and has the type DWord The second field is an array of char with RAS_MaxEntryName 1. Elements.
The delphi translation: THE DELPHI TRANSLATION:
Type
PRASENTRYNAME = ^ TRASENTRYNAME
TRASENTRYNAME = Record
DWSIZE: DWORD;
SzenTryName: array [0..ras_maxentryname] of char
end
Remember, you may not declare the array of char with a range from 0 to RAS_MaxEntryName 1. The reason is, that in C the number of elements is specified, but in Delphi the range of elements. Read more in the chapters about Arrays and Strings.
Back to Contents
3.6.2 Unions in Structure
C UNIONS in Structures Are Comparable to Variant Parts of Records in Delphi. Blocks Declared in A Union Structure Are Not Connecutive But overlaid.
Typedef struct _process_heap_entry {
PVOID LPDATA;
DWORD CBDATA;
Byte cboverhead;
BYTE IREGIONDEX;
Word wflags;
Union {
Struct {
Handle HMEM;
DWORD DWRESERVED [3];
Block;
Struct {
DWORD DWCOMMITTEDSIZE;
DWORD DWUNCOMMITTEDSIZE;
LPVOID LPFIRSTBLOCK; LPVOID LPLASTBLOCK;
} Region;
}
}} Process_heap_entry, * lpprocess_heap_entry, * pprocess_heap_entry
This is The Translation Into Delphi:
Type
PPROCESSHEAPENTRY = ^ TPROCESSHEAPENTRY;
TProcessHeapenTry = Record
LPDATA: POINTER;
CBDATA: DWORD;
CBOVERHEAD: BYTE;
IREGIONDEX: BYTE;
WFLAGS: WORD;
Case Integer of
0: (Block: Record
HMEM: Thandle
Reserved: array [0..2] of dword;
END);
1: (Region: Record
DWCommittedsize: DWORD;
Dwuncommittedsize: DWORD;
LpfirstBlock: Pointer;
Lplastblock: Pointer
END);
END;