C char类型到delphi的转换 [英] C char type to delphi conversion
问题描述
可能重复:
将C数组声明移植到Delphi
I正在将C代码转换为Delphi,并且我想转换变量声明,但我真的不知道。您能帮忙吗?
I'm converting a C code to Delp and I want to convert a variable declaration, but I really don't know.. Can you help?
char szImageName[BUFMAXLEN];
谢谢。
推荐答案
Delphi等效项是:
The Delphi equivalent is:
var
szImageName: array [0..BUFMAXLEN-1] of AnsiChar;
请注意使用 AnsiChar
而不是 Char
,因为在现代版本的Delphi中,通用类型 Char
的别名为2个字节 WideChar
。当然,如果您使用的是Unicode之前的Delphi,那么此警告就没有意义。
Take care to use AnsiChar
rather than Char
since in modern versions of Delphi the generic type Char
is aliased to the 2 byte WideChar
. Of course if you are on pre-Unicode Delphi then this warning is not pertinent.
语法上的最大区别是C中的所有数组的下限均为0 。在Delphi中,您可以指定所需的下限。当然,为了匹配C代码,我们将0指定为下限。
The biggest difference in the syntax is that all arrays in C have 0 as the lower bound. In Delphi you can specify whatever lower-bound you wish. Naturally to match the C code we specify 0 as our lower-bound.
这篇关于C char类型到delphi的转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!