国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 編程 > C++ > 正文

如何將C/C++程序轉(zhuǎn)譯成Delphi(六)

2019-11-18 18:50:18
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

3.4. Strings

In C, as in Delphi, a string is an array of char types. Often, a string declaration is used in combination with a constant declaration specifying the maximum string length, as the following example shows:

#define RAS_MaxEntryName 256#define RASENTRYNAMEA struct tagRASENTRYNAMEARASENTRYNAMEA{  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 struct (record) which contains a null-terminated string:

CHAR szEntryName[ RAS_MaxEntryName + 1 ];

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 types can be translated in two ways.

Method 1:

typedef enum _FINDEX_INFO_LEVELS {FindExInfoStandard,FindExInfoMaxInfoLevel} 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 PRoblematic:

typedef enum _ACL_INFORMATION_CLASS {AclRevisionInformation = 1,AclSizeInformation} ACL_INFORMATION_CLASS

The "= 1" in the declaration forces C to start with the ordinal value 1. This is not possible in Delphi.

There are two ways to solve the problem.

Solution a): Declare the enumeration as

TACLInformationClass = (_Fill0,                         AclRevisionInformation,                         AclSizeInformation);

Solution b): Translate the enumeration as

CONST  AclRevisionInformation = 1;  AclSizeInformation = 2;TYPE  TACLInformationClass = DWord;

That's no problem for this example. But in C it's possible to specify the ordinal value of each item of the 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


上一篇:如何將C/C++程序轉(zhuǎn)譯成Delphi(七)

下一篇:如何將C/C++程序轉(zhuǎn)譯成Delphi(五)

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
學(xué)習(xí)交流
熱門圖片

新聞熱點(diǎn)

疑難解答

圖片精選

網(wǎng)友關(guān)注

主站蜘蛛池模板: 会昌县| 温泉县| 南开区| 运城市| 蓬莱市| 龙江县| 阿克陶县| 宜州市| 木兰县| 桓台县| 江门市| 日照市| 九江市| 青冈县| 淮北市| 蒙阴县| 榆社县| 英山县| 武陟县| 康平县| 乌审旗| 祥云县| 绥德县| 鄂托克前旗| 固阳县| 集安市| 刚察县| 盐城市| 吕梁市| 南漳县| 融水| 新河县| 仪征市| 榆树市| 明星| 镇原县| 抚松县| 溧水县| 蚌埠市| 休宁县| 稷山县|