Little Helper
Little Helper

Reputation: 2456

Combine two Bytes to WideChar

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?

Upvotes: 3

Views: 995

Answers (2)

Ondrej Kelle
Ondrej Kelle

Reputation: 37221

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

Upvotes: 8

Lloyd
Lloyd

Reputation: 29668

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.

Upvotes: 3

Related Questions