OK, the thing turns out to be a little bit more complicated.
Your system locale is "es_ES.UTF-8", that is obviously UTF8 encoding, not cp1252.
Yes, you are right, but I wrote in my my first post that I also tested with the locale set to es_ES.ISO-8859-1, with the same result. For the tests I describe below I changed the locale again to ISO-8859-1.
Where do you find this function?
In the same unit as CP1252ToUTF8, LConvEncoding.
I made some more tests and found out something interesting.
The application where I'm getting those problems is a daemon-application, using package LazDaemon. It's a synchronization application, to transfer data between a database (from where the strings in ISO8859-1 codification come) to Windows-CE devices (where the strings are needed in UTF16 format).
I changed my main lpr file to include some debug output:
Program SmartPPCServer;
{$Define _UTFTEST_}
Uses
{$IFDEF UNIX}
{$IFDEF UseCThreads}
CThreads,
{$ENDIF}
cwstring,
{$ENDIF}
LazDaemon,
DaemonApp
{ add your units here }
{$IfDef _UTFTEST_}
, LConvEncoding, StrUtils, lclproc
{$EndIf}
, UnitSmartPPCDaemonMapper, UnitSmartPPCDaemon;
{$IFDEF WINDOWS}{$R SmartPPCServer.rc}{$ENDIF}
{$IfDef _UTFTEST_}
var
strISO8859_1, strUTF8, hexStr: AnsiString;
wStr: WideString;
{$EndIf}
begin
{$IfDef _UTFTEST_}
WriteLn('System encoding: ' + GetSystemEncoding);
// ISO8859_1 string: 'áéíóúüñÁÉÍÓÚÜѺª'
strISO8859_1 := #$E1#$E9#$ED#$F3#$FA#$FC#$F1#$C1#$C9#$CD#$D3#$DA#$DC#$D1#$BA#$AA;
SetLength(hexStr, Length(strISO8859_1) * 2);
BinToHex(PChar(strISO8859_1), PChar(hexStr), Length(strISO8859_1));
WriteLn('Source: ' + strISO8859_1 + ' [' + hexStr + ']');
strUTF8 := AnsiToUTF8(strISO8859_1);
SetLength(hexStr, Length(strUTF8) * 2);
BinToHex(PChar(strUTF8), PChar(hexStr), Length(strUTF8));
WriteLn('AnsiToUTF8: [' + hexStr + ']');
strUTF8 := CP1252ToUTF8(strISO8859_1);
SetLength(hexStr, Length(strUTF8) * 2);
BinToHex(PChar(strUTF8), PChar(hexStr), Length(strUTF8));
WriteLn('CP1252ToUTF8: [' + hexStr + ']');
wStr := UTF8ToUTF16(strUTF8);
SetLength(hexStr, Length(wStr) * 4);
BinToHex(PChar(PWideChar(wStr)), PChar(hexStr), Length(wStr) * 2);
WriteLn('UTF8ToUTF16: [' + hexStr + ']');
wStr := strISO8859_1;
SetLength(hexStr, Length(wStr) * 4);
BinToHex(PChar(PWideChar(wStr)), PChar(hexStr), Length(wStr) * 2);
WriteLn('Assignment: [' + hexStr + ']');
{$EndIf}
Application.Title:='SmartPPCServer';
Application.Initialize;
Application.Run;
end.
When running this application from the command line, everything is as expected:
firebird@PSERVER:~/bin> ./SmartPPCServer -r -t
System encoding: iso88591
Source: áéíóúüñÁÉÍÓÚÜѺª [E1E9EDF3FAFCF1C1C9CDD3DADCD1BAAA]
AnsiToUTF8: [C3A1C3A9C3ADC3B3C3BAC3BCC3B1C381C389C38DC393C39AC39CC391C2BAC2AA]
CP1252ToUTF8: [C3A1C3A9C3ADC3B3C3BAC3BCC3B1C381C389C38DC393C39AC39CC391C2BAC2AA]
UTF8ToUTF16: [E100E900ED00F300FA00FC00F100C100C900CD00D300DA00DC00D100BA00AA00]
Assignment: [E100E900ED00F300FA00FC00F100C100C900CD00D300DA00DC00D100BA00AA00]
Terminado (killed)
PSERVER:/ibdata/bin # ps aux | grep SmartPPC
firebird 5611 0.1 0.4 54100 4740 pts/9 Sl+ 14:56 0:00 ./SmartPPCServer -r -t
But when starting the daemon, something goes wrong:
PSERVER:/ibdata/bin # /etc/init.d/smartppcserver start
Starting smartppcserver System encoding: ansi
Source: áéíóúüñÁÉÍÓÚÜѺª [E1E9EDF3FAFCF1C1C9CDD3DADCD1BAAA]
AnsiToUTF8: [3F3F3F3F3F3F3F3F3F3F3F3F3F3F3F3F]
CP1252ToUTF8: [C3A1C3A9C3ADC3B3C3BAC3BCC3B1C381C389C38DC393C39AC39CC391C2BAC2AA]
UTF8ToUTF16: [E100E900ED00F300FA00FC00F100C100C900CD00D300DA00DC00D100BA00AA00]
Assignment: [3F003F003F003F003F003F003F003F003F003F003F003F003F003F003F003F00]
done
PSERVER:/ibdata/bin # ps aux | grep SmartPPC
firebird 5859 0.1 0.4 51620 4608 pts/8 Sl 15:44 0:00 /ibdata/bin/SmartPPCServer -r -t
I don't see the difference, the process is running under the same user in both cases.
The daemon is started the standard OpenSuse way:
[...]
SMARTPPCSERVER_BIN=/ibdata/bin/SmartPPCServer
SMARTPPCSERVER_OPTIONS="-r -t"
[...]
/sbin/startproc -u firebird -e $SMARTPPCSERVER_BIN $SMARTPPCSERVER_OPTIONS
[...]