如何将C/C++程序转译成Delphi(二)

王朝delphi·作者佚名  2006-01-08
窄屏简体版  字體: |||超大  

. Anatomy of a C Header

Back to contents --

Back to contents

## to do

2. Conversion Basics Back to contents

--

2.1. Naming

The naming in converted header files should follow Borland's style as far as possible. This means, keep the original names, but make them more Delphi-like.

How should the C names be translated into Delphi?

The C-programmer usually uses upper case letters for type identifiers, e.g. MY_TYPE. In Delphi, a type identifier has a T-prefix followed by the name of the type in mixed (proper) case. Underscores are not used. The Delphi-like translation of the C type identifier MY_TYPE is TMyType.

In C older header files the pointer-type is named LPMY_TYPE. In translation to Delphi it should be PMyType to conform with Borland's style.

Constants are usually named identically to the original name, including upper case letters and underscores.

A few examples:

C

Delphi-Translation

typedef struct _IMAGE_FILE_HEADER {

WORD Machine;

WORD NumberOfSections;

DWORD TimeDateStamp;

DWORD PointerToSymbolTable;

DWORD NumberOfSymbols;

WORD SizeOfOptionalHeader;

WORD Characteristics;

} IMAGE_FILE_HEADER,

*PIMAGE_FILE_HEADER;

type

PImageFileHeader = ^TImageFileHeader;

TImageFileHeader = packed record

Machine: Word;

NumberOfSections: Word;

TimeDateStamp: DWORD;

PointerToSymbolTable: DWORD;

NumberOfSymbols: DWORD;

SizeOfOptionalHeader: Word;

Characteristics: Word;

end;

#define LANG_NEUTRAL 0x00

#define LANG_AFRIKAANS 0x36

#define LANG_ALBANIAN 0x1C

#define LANG_ARABIC 0x01

#define LANG_BASQUE 0x2D

#define LANG_BELARUSIAN 0x23

#define LANG_BULGARIAN 0x02

#define LANG_CATALAN 0x03

#define LANG_CHINESE 0x04

CONST

LANG_NEUTRAL = $00;

LANG_AFRIKAANS = $36;

LANG_ALBANIAN = $1C;

LANG_ARABIC = $01;

LANG_BASQUE = $2D;

LANG_BELARUSIAN = $23;

LANG_BULGARIAN = $02;

LANG_CATALAN = $03;

LANG_CHINESE = $04;

Back to contents --

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航