The following code is debugged on Delphi 7, mainly using MultibyTowideChar Function UnicodeEncode (str: string; codepage: widestring; var len: integer; begin len: = length (str) 1; setLENGTH (Result, Len: = MultibytetowideChar (CodePage, 0, Pchar (STR), - 1, PWIDECHAR (RESULT), LEN); SETLENGTH (Result, Len-1); // end is # 0nd;
Function UNICODECODE (STR: WIDESTRING; CODEPAGE: STRING; VAR LEN: Integer; Begin Len: = Length (STR) * 2 1; // One for # 0 setlength; len: = WideChartomultibyte CodePage, 0, PWIDECHAR (STR), - 1, Pchar (Result), Len, NIL, NIL; setLENGTH (Result, LEN-1);
function Gb2Big5 (Str: string): string; begin SetLength (Result, Length (Str)); LCMapString (GetUserDefaultLCID, LCMAP_TRADITIONAL_CHINESE, PChar (Str), Length (Str), PChar (Result), Length (Result)); Result: = UnicodeDecode (UnicodeEncode (Result, 936), 950); END;
function Big52Gb (Str: string): string; begin Str: = UnicodeDecode (UnicodeEncode (Str, 950), 936); SetLength (Result, Length (Str)); LCMapString (GetUserDefaultLCID, LCMAP_SIMPLIFIED_CHINESE, PChar (Str), Length (Str ), Pchar (result), longeth (result);
The key uses the UnicodeToutf8 function function function UTF8Encode (const ws: widestring): utf8string; var l: integer; temp: utf8 confing; begin result: = '; if WS =' 'TENE EXIT; SETLENGTH (Temp, Length (WS) * 3); // SETLENGTH INCLUDES SPACE for Null Terminator L: = UnicoDetOutf8 (Pchar (Temp), Length (Temp) 1, PWIDECHAR (WS), Length (WS)); if L> 0 THEN SETLENGTH (Temp, L- 1) Else Temp: = ''; result: = temp;