By default, Indy uses 7bit ASCII as its character encoding (for compatibility with various Internet protocols). To use a different character encoding, you need to either:
set the IOHandler.DefStringEncoding
property before doing any reading/writing. The string-based I/O methods will then use this encoding by default.
// note: use TIdTextEncoding.UTF8 if not using Indy 10.6 or later...
AContext.Connection.IOHandler.DefStringEncoding := IndyTextEncoding_UTF8;
use the optional AByteEncoding
parameter of the various string-based I/O methods, including WriteLn()
.
// note: use TIdTextEncoding.UTF8 if not using Indy 10.6 or later...
AContext.Connection.IOHandler.WriteLn('Usuário não existe', IndyTextEncoding_UTF8);
Needless to say, the client will also have to use an equivalent encoding when reading the server's data so it can decode the transmitted bytes back to Unicode. For example:
// note: use TIdTextEncoding.UTF8 if not using Indy 10.6 or later...
Client.IOHandler.DefStringEncoding := IndyTextEncoding_UTF8;
Or:
// note: use TIdTextEncoding.UTF8 if not using Indy 10.6 or later...
S := Client.IOHandler.ReadLn(IndyTextEncoding_UTF8);