这里有一个简单的问题。如何在Delphi-7中将WideChar
转换为2xByte
?我搜索了互联网和StackOverflow,但没有找到结果...
David 给出了首选的方法,即,
var
b1, b2: Byte;
wc: WideChar;
...
b1 := WordRec(wc).Lo;
b2 := WordRec(wc).Hi;
还有几个其他选项(只是为了好玩):
b1 := Lo(Word(wc));
b2 := Hi(Word(wc));
和
b1 := Byte(wc);
b2 := Byte(Word(wc) shr 8);
和
b1 := PByte(@wc)^;
b2 := PByte(NativeUInt(@wc) + 1)^;
和
var
wc: WideChar;
bytes: WordRec absolute wc;
begin
// Magic! The bytes are already found in bytes.Lo and bytes.Hi!
var
b1, b2: Byte;
wc: WideChar;
....
b1 := WordRec(wc).Lo;
b2 := WordRec(wc).Hi;
WordRec
转换。但我仍然明确表示你是第一个提出这个解决方案的人。 - Andreas Rejbrand