Recent

Author Topic: FPC 2.6.2 / Wince : String to UnicodeString type casting  (Read 2326 times)

swierzbicki

  • Full Member
  • ***
  • Posts: 177
FPC 2.6.2 / Wince : String to UnicodeString type casting
« on: April 24, 2014, 09:06:41 am »
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: [Select]
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;
Lazarus 1.6.2
fpc 3.0.0
wince/win32/win64
delphi berlin