WideChar to Bytes?

I have a simple question. How to convert WideChar to 2x Byte in Delphi - 7? I searched the Internet and StackOverflow , but with no results ...

+6
source share
2 answers

David gave you the preferred method, 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! 
+12
source

Many ways to do this. For example, my personal choice:

 var b1, b2: Byte; wc: WideChar; .... b1 := WordRec(wc).Lo; b2 := WordRec(wc).Hi; 
+7
source

All Articles