Am 10.07.2012 09:43, schrieb Antonio Fortuny:
Hi All.

Assuming that I'm modifying an application which
- will run on Win32 and WinCE (handheld device) (X-compilation, 2 targets)
- all string variables have previously been defined as String;
- WinCE (5.?) is UNICODE

Just to make sure that I'm on the right way, do you see someting wrong
in the following sentences:

- all components using text (TLabel, TButton, TEdit, etc) use WideStrings

Wrong. All components [provided by the LCL] use "AnsiString" with UTF-8 encoding on every platform/widgetset. Please see also http://wiki.lazarus.freepascal.org/LCL_Unicode_Support

- I need to convert (using conditional code) from string to WideString
when compiling for WinCE, like

You only need to convert if you have text that is not encoded in UTF-8. Then you should use UTF8ToSys/SysToUTF8 or AnsiToUTF8/UTF8ToAnsi.


Example:
function ShowSomething(const Msg: string): Boolean; <<<--------
unchanged function definition
var
{$IFDEF WINCE}
wStr: WideString;
{$ELSE}
wStr: String;
{$ENDIF}
begin
result := False;
{$IFDEF WINCE}
wStr := UnicodeString(msg);
{$ELSE}
wStr := msg;
{$ENDIF}
ALabel.Caption := wStr;
// I know, the Caption could be assigned immediately instead of passing
through a variable
// this is just an example
...
Result := True
end;

Thanks for your remarks

function ShowSomething(const Msg: String): Boolean;
begin
  result := False;
  ALabel.Caption := AnsiToUTF8(Msg); // if Msg is encoded in Ansi
  ALabel.Caption := Msg; // if Msg is already UTF-8 encoded
  ...
  Result := True;
end;

Regards,
Sven

--
_______________________________________________
Lazarus mailing list
[email protected]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply via email to