Forum > General

FPC 2.6.2 / Wince : String to UnicodeString type casting

(1/1)

swierzbicki:
Hello,

What is the best way to type cast a string to an Unicode string ?
Here is a code example that fails under winCE (i'm trying to make Indy library works under Wince).
Problem is that getaddrinfo is failing... It is working when defining LTemp as String....


--- Code: ---type
  {$IFDEF DOTNET}
  TIdUnicodeString = System.String;
  {$ELSE}
    {$IFDEF HAS_UnicodeString} <==== DEFINED
  TIdUnicodeString = UnicodeString;
    {$ELSE}
  TIdUnicodeString = WideString;
    {$ENDIF}
  {$ENDIF}   
...

var
  LHostName: String;
  {$IFDEF UNICODE_BUT_STRING_IS_ANSI} <==== DEFINED
  LTemp: TIdUnicodeString;
  {$ENDIF} ...
Begin
...
  {$IFDEF UNICODE_BUT_STRING_IS_ANSI}
  LTemp := TIdUnicodeString(LHostName); // explicit convert to Unicode
  {$ENDIF}

  RetVal := getaddrinfo(
    {$IFDEF UNICODE_BUT_STRING_IS_ANSI}PWideChar(LTemp){$ELSE}PChar(LHostName){$ENDIF},
    nil, @Hints, @LAddrInfo);...
End;
--- End code ---

Navigation

[0] Message Index

Go to full version