Subject | RE: [firebird-support] UDF & unicode_FSS & delphi widestring ... |
---|---|
Author | Svend Meyland Nicolaisen |
Post date | 2007-12-17T13:57:35Z |
The UNICODE_FSS encoding is a subset of the UTF-8 encoding. If you are using
Firebird 2 you should consider using the UTF8 character set instead of
UNICODE_FSS. The encoding of WideChars and WideStrings in Delphi is UTF-16
LE. You will therefor need to convert between UTF-8 and UTF-16 LE.
The declaration you need to use is
function F_Unicode_ECHO(Str: PChar): PChar;cdecl; export;
To convert between UTF-8 and UTF-16 LE you can do something like this (note
I havent tried to compile the code):
function F_StringTo2WHex(const Str: PChar): PChar;
var
res : wideString;
Len: Integer;
S: Pchar;
Begin
Len:=StrLen(Str);
SetLength(Res,Len);
Len:=MultiByteToWideChar(CP_UTF8,0,Str,-1,PWideChar(Res),Len);
if Len=0
Some Error Handling
else
begin
SetLength(Res,Len);
Do what you want with the widestring Res
Len:=Length(Res)*8;
S:=ib_util_malloc(Len);
Len:=WideCharToMultiByte(CP_UTF8,0,PWideChar(Res),-1,PChar(S),Len,nil,nil);
if Len=0 then
Some error handling
else
Result:=S;
end;
end;
/Svend
________________________________
From: firebird-support@yahoogroups.com
[mailto:firebird-support@yahoogroups.com] On Behalf Of mnavahan
Sent: 16. december 2007 12:16
To: firebird-support@yahoogroups.com
Subject: [firebird-support] UDF & unicode_FSS & delphi widestring ...
hi
i write own udf in delphi base in Greg Deatz' UDFlib
nice and easy ...
but :
now i need send some unicode string to my function in delphi and return
unicode string to firebird via UDF
for example function below echo text from udf:
1. must use PChar param or PWidechar ?
function F_Unicode_ECHO(const Str: PChar): PChar;cdecl; export;
function F_Unicode_ECHO(const Str: PWideChar): PWideChar;cdecl; export;
2.how convert this udf in delphi to widestring and return it :
function F_StringTo2WHex(const Str: PChar): PChar;
var
res : wideString;
begin
S := widestring(Str);
result := MakeResultString(PChar(s), nil, 0);
end;
sorry up code no work ! can help me ?
Firebird 2 you should consider using the UTF8 character set instead of
UNICODE_FSS. The encoding of WideChars and WideStrings in Delphi is UTF-16
LE. You will therefor need to convert between UTF-8 and UTF-16 LE.
The declaration you need to use is
function F_Unicode_ECHO(Str: PChar): PChar;cdecl; export;
To convert between UTF-8 and UTF-16 LE you can do something like this (note
I havent tried to compile the code):
function F_StringTo2WHex(const Str: PChar): PChar;
var
res : wideString;
Len: Integer;
S: Pchar;
Begin
Len:=StrLen(Str);
SetLength(Res,Len);
Len:=MultiByteToWideChar(CP_UTF8,0,Str,-1,PWideChar(Res),Len);
if Len=0
Some Error Handling
else
begin
SetLength(Res,Len);
Do what you want with the widestring Res
Len:=Length(Res)*8;
S:=ib_util_malloc(Len);
Len:=WideCharToMultiByte(CP_UTF8,0,PWideChar(Res),-1,PChar(S),Len,nil,nil);
if Len=0 then
Some error handling
else
Result:=S;
end;
end;
/Svend
________________________________
From: firebird-support@yahoogroups.com
[mailto:firebird-support@yahoogroups.com] On Behalf Of mnavahan
Sent: 16. december 2007 12:16
To: firebird-support@yahoogroups.com
Subject: [firebird-support] UDF & unicode_FSS & delphi widestring ...
hi
i write own udf in delphi base in Greg Deatz' UDFlib
nice and easy ...
but :
now i need send some unicode string to my function in delphi and return
unicode string to firebird via UDF
for example function below echo text from udf:
1. must use PChar param or PWidechar ?
function F_Unicode_ECHO(const Str: PChar): PChar;cdecl; export;
function F_Unicode_ECHO(const Str: PWideChar): PWideChar;cdecl; export;
2.how convert this udf in delphi to widestring and return it :
function F_StringTo2WHex(const Str: PChar): PChar;
var
res : wideString;
begin
S := widestring(Str);
result := MakeResultString(PChar(s), nil, 0);
end;
sorry up code no work ! can help me ?