PSDEVS
PSDEVS

Reputation: 99

Write a unicode text at inifiles

How i can write the unicode string "Внимание" on a .inifile? how i'm writing:

    Escreve := TIniFile.Create(Patch + 'File.ini');
    Escreve.WriteString('Informations', 'Patch',  ParamStr(0));

The folder name is "Внимание" and at .inifile show ????????

Upvotes: 1

Views: 959

Answers (1)

Remy Lebeau
Remy Lebeau

Reputation: 595329

On Windows, TIniFile internally uses the Win32 PrivateProfile API (in this case, WritePrivateProfileStringA() in Delphi 2007 and earlier, and WritePrivateProfileStringW() in Delphi 2009 and later). WritePrivateProfileStringA() does not support Unicode at all, and WritePrivateProfileStringW() writes Unicode data only if the INI file already exists and was created with a UTF-16 BOM, otherwise it writes ANSI data instead.

If you are using Delphi 2009+, TMemIniFile allows you to specify a TEncoding for the desired charset, such as TEncoding.UTF8 or TEncoding.Unicode (UTF-16), eg:

Escreve := TMemIniFile.Create(Patch + 'File.ini', TEncoding.UTF8);
Escreve.WriteString('Informations', 'Patch',  ParamStr(0));

Upvotes: 5

Related Questions