Page 1 of 1

[patch_done] Bug in ZSysUtils.UnicodeToAnsi function

Posted: 28.11.2008, 22:59
by mariuszekpl
I found small BUG in function UnicodeToAnsi.
When i use UnicodeToAnsi (with BUG) it result string without unicode chars. Only ????



Is

Code: Select all

{$IFDEF ZEOS_FULL_UNICODE}
{**
  Converts Unicode strings to Ansi (Delphi 2009 Up)
}
function UnicodeToAnsi(const UnicodeString: string): AnsiString;
begin
  result := AnsiString(UnicodeString);
end;
{$ENDIF}
Should be:

Code: Select all

{$IFDEF ZEOS_FULL_UNICODE}
{**
  Converts Unicode strings to Ansi (Delphi 2009 Up)
}
function UnicodeToAnsi(const UnicodeString: string): Utf8string;
begin
   result := Utf8string(UnicodeString);
end;
{$ENDIF}
UTF8String = type AnsiString(65001);
but UTF8String != AnsiString

Posted: 01.12.2008, 11:18
by gto
Hum, there is this bug, yes, but this function was created with the idea that converting from Unicode to Ansi is a losing function, you will loose something. Delphi was using Ansi as standard, and TStringField still using Ansi (as you writed, too).

There's some places where this function still usefull?

If yes, I think we can create a new function, UnicodeToUTF8, so things will stay with the names OK ;)

Posted: 03.12.2008, 11:19
by mdaems
mariuszekpl,

Reaction?
- Rename the function?
- Keep both functions?

Mark

Posted: 07.12.2008, 03:04
by mariuszekpl
Delete both.
We dont need UnicodeToAnsi function and UnicodeToUTF8 is standard delphi function (in delphi 2009)
Name UnicodeToAnsi is very strange :( and can mislead


replace all place UnicodeToAnsi with UTF8String

example:

Code: Select all

    {$IFDEF ZEOS_FULL_UNICODE}
    GetPlainDriver.db_execute_imm(GetDBHandle, PAnsiChar(UnicodeToAnsi(SQL)));
    {$ELSE}
    GetPlainDriver.db_execute_imm(GetDBHandle, PAnsiChar(SQL)); 
    {$ENDIF}      

Code: Select all

    {$IFDEF ZEOS_FULL_UNICODE}
    GetPlainDriver.db_execute_imm(GetDBHandle, PAnsiChar(UTF8String (SQL)));
    {$ELSE}
    GetPlainDriver.db_execute_imm(GetDBHandle, PAnsiChar(SQL)); 
    {$ENDIF}      

Posted: 07.12.2008, 09:39
by mdaems
SVN rev. 537.

Posted: 08.12.2008, 13:12
by mariuszekpl