سؤال

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;
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top