3.4. Strings
IN C, AS in Delphi, A String IS AN ARRAY of CHAR TYPES. OFTEN, A STRING DECLATION IS USED IN Combination With a constant declaration specifying the maximum string length, as the folowing example shows:
#define ras_maxentryname 256
#define RasentryNamea Struct TagrasentryNamea
RasentryNamea
{
DWORD DWSIZE;
CHAR SZENTRYNAME [RAS_MAXENTRYNAME 1];
}
THE FIRST LINE DECLARES A constant ras_maxentryname with the value 256 specifying the maximum length of the string. The Lines After IT Declare A Null-Terminated String:
CHAR SZENTRYNAME [RAS_MAXENTRYNAME 1];
The delphi translation: THE DELPHI TRANSLATION:
SzenTryName: array [0..ras_maxentryname] of char;
Why not Array [0..RAS_MaxEntryName 1] of Char? Recall that a C array starts with 0 and the declaration specifies the number of elements. Thus, Array [0..RAS_MaxEntryName 1] in Delphi is equivalent to [RAS_MaxEntryName 2] IN C.
Back to Contents
3.5. ENUMERATIONS - Two Methods
ENUMERATED TWES CAN BE Translated in Two Ways.
Method 1:
Typedef enum _findex_info_levels {
FINDEXINFOSTANDARD,
FINDEXINFOMAXINFOLEVELEVEL
FINDEX_INFO_LEVELS;
THIS Part of a c-header file translates Easily to Delphi:
Type
Tfindexinfolevels = (FINDEXINFOSTANDARD,
FINDEXINFOMAXINFOLEVEL);
The Ordinal Value of The Item Findexinfostandard IS 0. in Delphi Each Enumeration Starts with 0.
Method 2:
The Following C-Declaration is more problem:
TypedEf Enum _ACL_INFORMATION_CLASS {
AclRevisionInformation = 1,
ACLSIZEINFORMATION
} ACL_INFORMATION_CLASS
THE "= 1" in the declaration forces c to start with the order value 1. this is not Possible in Delphi.
There is the question.
Solution a): declare the enumeration ASTACLINFORMATIONCLASS = (_fill0,
AclRevisionInformation,
Aclsizeinformation;
Solution B): Translate The Enumeration AS
Const
AclRevisionInformation = 1;
AclsizeInformation = 2;
Type
TaclinformationClass = DWORD;
That's no questionm for this Example. But in c it's possible to specify the order of the y ENUMERATION, for example:
Typedef enum _ENUMEXAMPLE {
Item1 = 5,
Item2 = 10,
ENUMEXAMPLE;
Using Enumeration in Delphi The Declaration Would Have to Be Done Like this:
Tenumexample = (_fill0,
_Fill1,
_Fill2,
_Fill3,
_Fill4,
Item1,
_Fill6,
_Fill7,
_Fill8,
_Fill9,
Item2);
This is hard to read and clumsy to maintain.
This Works Better:
Const
Item1 = 5;
Item2 = 10;
Type
Tenumexample = DWORD;
Back to Contents