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

原创 2001年07月24日 13:24:00
. Anatomy of a C Header


Back to contents

## to do

2. Conversion Basics

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;

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

Conversion Tutorial Draft 4 27 JANUARY, 1998by Andreas Prucha Contents Anatomy of a C Header Convers...
  • mysine
  • mysine
  • 2001年07月24日 13:22
  • 616

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

1. Anatomy of a C HeaderBack to contents -->Back to contents ## to do2. Conversion Basics Back to co...
  • mysine
  • mysine
  • 2001年07月24日 13:28
  • 1092

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

2.2. Unit dependencies Back to contents -->C and C++ use #include to include header files in another...
  • mysine
  • mysine
  • 2001年07月24日 13:26
  • 690

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

7.2. Dynamic LinkingDynamic Linking is used to link the DLL at runtime.Handling Static and Dynamic L...
  • mysine
  • mysine
  • 2001年07月24日 13:45
  • 577

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

5. Conditionals###ToDoBack to contents -->Back to contents 6. Functions6.1. BasicsLets use the follo...
  • mysine
  • mysine
  • 2001年07月24日 13:35
  • 608

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

Here is a real-world example from the winnt.h, which is not possible to translate to a native enumer...
  • mysine
  • mysine
  • 2001年07月24日 13:30
  • 508

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

4. MacrosIn C its possible to define macros. Macros are not available in Delphi, so functions must b...
  • mysine
  • mysine
  • 2001年07月24日 13:34
  • 599

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

7. LinkingThere are two ways to link a DLL and import a function. Static linking is very easy and th...
  • mysine
  • mysine
  • 2001年07月24日 13:39
  • 655

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

Case Integer of starts the variant part of the record. Each variant is identified by an ordinal valu...
  • mysine
  • mysine
  • 2001年07月24日 13:32
  • 624

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

3.4. StringsIn C, as in Delphi, a string is an array of char types. Often, a string declaration is u...
  • mysine
  • mysine
  • 2001年07月24日 13:29
  • 596
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:如何将C/C++程序转译成Delphi(二)
举报原因:
原因补充:

(最多只允许输入30个字)