Question

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?

Was it helpful?

Solution

WChar := WideChar(MakeWord(B1, B2));

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top