FireWind
Malware Analyst
		- Joined
 - Dec 26, 2018
 
- Messages
 - 304
 
- Reaction score
 - 321
 
Chr equivalent for Unicode in Delphi 7
Jeroen Pluimers
	
	
		
			
	
			
			Jeroen Pluimers
[SHOWTOGROUPS=4,20]
Q
I need to initialize a Widestring in Delphi 7 but I can’t use chrfunction which is ANSI
	
	
	
		
What can I use, then ?
A
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:
	
	
	
		
but you cannot concatenate WideChar. So this is a compiler error:
	
	
	
		
You could use a helper function to get the job done:
	
	
	
		
Then you can call it like this:
	
	
	
		
[/SHOWTOGROUPS]
		Q
I need to initialize a Widestring in Delphi 7 but I can’t use chrfunction which is ANSI
		Code:
	
	var
  ws : Widestring;
begin
 ws := chr($FFFF) + chr($FFFF) + chr($FFFF);
end;
	A
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:
		Code:
	
	WideChar($FFFF)
	
		Code:
	
	WideChar($FFFF) + WideChar($FFFF)
	
		Code:
	
	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;
	
		Code:
	
	ws := InitialiseWideString([$0054, $0069, $006D, $0065, $0020, $0074, $006F, $0020, $0075, $0070, $0067, $0072, $0061, $0064, $0065]);