chr equivalent for Unicode in Delphi 7
Asked Answered
F

1

2

I need to initialize a Widestring in Delphi 7 but I can't use chr function which is ANSI

var
  ws : Widestring;
begin

 ws := chr($FFFF) + chr($FFFF) + chr($FFFF);

end;

What can I use, then ?

Thanks

Fluorene answered 18/2, 2013 at 8:58 Comment(1)
I don't have a Delphi compiler here, but can't you use something like a #$... character constant in the string? By the way, U+FFFF is an illegal character in Unicode; don't use it ever.Devoted
P
10

I'm not sure there's a simply way to do what you wish. You can convert a Word into a WideChar with a simple cast:

WideChar($FFFF)

but you cannot concatenate WideChar. So this is a compiler error:

WideChar($FFFF) + WideChar($FFFF)

You could use a helper function to get the job done:

function InitialiseWideString(const chars: array of Word): WideString;
var
  i: Integer;
begin
  SetLength(Result, Length(chars));
  for i := 0 to high(chars) do
    Result[i+1] := WideChar(chars[i]);
end;

Then you can call it like this:

ws := InitialiseWideString([$0054, $0069, $006D, $0065, $0020, $0074, $006F, 
  $0020, $0075, $0070, $0067, $0072, $0061, $0064, $0065]);
Player answered 18/2, 2013 at 9:7 Comment(3)
Found easter egg: "Time to upgrade" :-).Terbia
@Terbia Ah, nice to know that it wasn't all for nothing!!Player
Nice one, will add it to the company core library ;)Burnham

© 2022 - 2024 — McMap. All rights reserved.