3

Is it possible to combine two Bytes to WideChar and if yes, then how?
For example, letter "ē" in binary is 00010011 = 19 and 00000001 = 1, or 275 together.

var
  WChar: WideChar;
begin
  WChar := WideChar(275); // Result is "ē"


var
  B1, B2: Byte;
  WChar: WideChar;
begin
  B1 := 19;
  B2 := 1;
  WChar := CombineBytesToWideChar(B1, B2); // ???

How do I get WideChar from two bytes in Delphi?

Little Helper
  • 2,419
  • 9
  • 37
  • 67

2 Answers2

8
WChar := WideChar(MakeWord(B1, B2));
Ondrej Kelle
  • 36,941
  • 2
  • 65
  • 128
3

You should just be able to create a type and cast:

type
  DoubleByte = packed record
    B1: Byte;
    B2: Byte;
  end;

var
  DB: DoubleByte;
  WC: WideChar;
begin
  DB.B1 := 19;
  DB.B2 := 1;

  WC = WideChar(DB);
end;

Failing a cast you can use Move() instead and simply copy the memory.

Lloyd
  • 29,197
  • 4
  • 84
  • 98