delphinumberswidestring

How pass word number to widestring?


First of all I am sorry that I cannot better to describe my problem.

What I have is Word number 65025 which is 0xFE01 or 11111110 00000001 in binary. And I want to pass the value to wstr Word => 11111110 00000001.

I found that using typecast does not work.

And one more question here. If I want to add another number like 10000 => 0x03E8 how to do it. So in the result the widestring should refer to values 0xFE01 0x03E8.

And then, how to retrieve the same numbers from widestring to word back?

var wstr: Widestring;
wo: Word;
begin
  wo := 65025;
  wstr := Widestring(wo);
  wo := 10000;
  wstr := wstr + Widestring(wo);
end

Edit:

I'm giving another, simpler example of what I want... If I have word value 49, which is equal to ASCII value 1, then I want the wstr be '1' which is b00110001 in binary terms. I want to copy the bits from word number to the string.


Solution

  • It looks like you want to interpret a word as a UTF-16 code unit. In Unicode Delphi you would use the Chr() function. But I suspect you use an ANSI Delphi. In which case cast to WideChar with WideChar(wo).