它很容易定义一个大小为3的字符串(在旧的delphi代码中)
st:string[3];现在,我们希望将代码移至ansi
st:ansiString[3];将无法正常工作!
并为进一步oem类型
st:oemString[3];同样的问题,在哪里
type OemString = Type AnsiString(CP_OEMCP);怎么能声明一个固定长度的ansi字符串和新的oem类型?
更新:我知道它会创建一个固定长度的字符串。 它是防止错误的软件设计的一部分,对于程序来说是必不可少的。
Its easy to define a string at the size of 3 (in old delphi code)
st:string[3];now, we wish to move the code to ansi
st:ansiString[3];won't work!
and for adcanced oem type
st:oemString[3];same problem, where
type OemString = Type AnsiString(CP_OEMCP);how could be declared a fixed length ansi string and the new oem type?
update: i know it will create a fixed length string. it is part of the design of the software to protect against mistakes, and is essential for the program.
最满意答案
你不需要定义一个AnsiString的大小。
符号
string[3]是用于Pascal(和Delphi 1)使用的短字符串,它主要用于传统目的。
短字符串的长度可以是1到255个字节。 第一个(“隐藏”)字节包含长度。
AnsiString是一个指向字符缓冲区的指针(终止0)。 它有一些像引用计数一样的内部魔法。 而且您可以安全地将字符添加到现有的字符串,因为编译器会为您处理所有令人讨厌的细节。
UnicodeStrings与AnsiStrings类似,但带有Unicode字符(本例中为2个字节)。 现在默认字符串(Delphi 2009)映射到UnicodeString。
类型AnsiString有一个构造来添加一个代码页(用于定义127以上的字符),因此CP_OEMCP:
OemString = Type AnsiString(CP_OEMCP);You don't need to define the size of an AnsiString.
The notation
string[3]is for short strings used by Pascal (and Delphi 1) and it is mostly kept for legacy purposes.
Short strings can be 1 to 255 bytes long. The first ("hidden") byte contains the length.
AnsiString is a pointer to a character buffer (0 terminated). It has some internal magic like reference counting. And you can safely add characters to an existing string because the compiler will handle all the nasty details for you.
UnicodeStrings are like AnsiStrings, but with unicode chars (2 bytes in this case). The default string now (Delphi 2009) maps to UnicodeString.
the type AnsiString has a construct to add a codepage (used to define the characters above 127) hence the CP_OEMCP:
OemString = Type AnsiString(CP_OEMCP);更多推荐
发布评论