Domanda

I have simple question here. How to convert WideChar to 2xByte in Delphi - 7? I searched the internet and the StackOverflow but with no results...

È stato utile?

Soluzione

David gave you the preferable way, namely,

var
  b1, b2: Byte;
  wc: WideChar;

...

b1 := WordRec(wc).Lo;
b2 := WordRec(wc).Hi;

A few other options (just for fun):

b1 := Lo(Word(wc));
b2 := Hi(Word(wc));

and

b1 := Byte(wc);
b2 := Byte(Word(wc) shr 8);

and

b1 := PByte(@wc)^;
b2 := PByte(NativeUInt(@wc) + 1)^;

and

var
  wc: WideChar;
  bytes: WordRec absolute wc;

begin

  // Magic! The bytes are already found in bytes.Lo and bytes.Hi!

Altri suggerimenti

Lots of ways to do this. For example my personal choice would be:

var
  b1, b2: Byte;
  wc: WideChar;

....

b1 := WordRec(wc).Lo;
b2 := WordRec(wc).Hi;
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top