[patch_done] Bug in ZSysUtils.UnicodeToAnsi function

The alpha/beta tester's forum for ZeosLib 7.0.x series

Report problems concerning our Delphi 2009+ version and new Zeoslib 7.0 features here.

This is a forum that will be removed once the 7.X version goes into stable!!

Moderators: gto, EgonHugeist, olehs

Locked
mariuszekpl
Senior Boarder
Senior Boarder
Posts: 54
Joined: 30.09.2008, 10:59

[patch_done] Bug in ZSysUtils.UnicodeToAnsi function

Post 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
gto
Zeos Dev Team
Zeos Dev Team
Posts: 278
Joined: 11.11.2005, 18:35
Location: Porto Alegre / Brasil

Post 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 ;)
Use the FU!!!!!IN Google !

gto's Zeos Quick Start Guide

Te Amo Taís!
User avatar
mdaems
Zeos Project Manager
Zeos Project Manager
Posts: 2766
Joined: 20.09.2005, 15:28
Location: Brussels, Belgium
Contact:

Post by mdaems »

mariuszekpl,

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

Mark
Image
mariuszekpl
Senior Boarder
Senior Boarder
Posts: 54
Joined: 30.09.2008, 10:59

Post 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}      
User avatar
mdaems
Zeos Project Manager
Zeos Project Manager
Posts: 2766
Joined: 20.09.2005, 15:28
Location: Brussels, Belgium
Contact:

Post by mdaems »

SVN rev. 537.
mariuszekpl
Senior Boarder
Senior Boarder
Posts: 54
Joined: 30.09.2008, 10:59

Post by mariuszekpl »

Locked