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

博客主要介绍了将 C 头文件转换为 Delphi 风格的命名规则。转换后的头文件命名应尽量遵循 Borland 风格,C 类型标识符转换时,Delphi 用 T 前缀加混合大小写命名;C 指针类型转换为 Delphi 时用 P 开头;常量通常保持原名。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

. 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:

CDelphi-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;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值