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...
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!
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With