简体   繁体   中英

DELPHI INDY - Can not find parameter to activate UTF8 encoding/decoding

I'm using Delphi 10.3 and have created a TIdTCPServer and a client. I found that Unicode characters like ÅÄÖ are changed when sent.

ContexClient.Connection.IOHandler.DefStringEncoding := IndyTextEncoding_UTF8;
ContexClient.Connection.IOHandler.WriteLn('abcÅÄÖ');

In the code above, I tried to fix that with the DefStringEncoding property, but the compiler doesn't find IndyTextEncoding_UTF8 .

I've no idea what to do to get it working.

Any idea?

Indy's default encoding is US-ASCII. That can be changed at runtime using the GIdDefaultTextEncoding variable in Indy's IdGlobal unit. You can set it to encUTF8 , for instance.

That is why you see non-ASCII characters being changed. Using the TIdIOHandler.DefStringEncoding property is one solution for that. IndyTextEncoding_UTF8 is declared in the IdGlobal unit. Make sure that unit is added to your uses clause.

TIdIOHandler.WriteLn() itself also has an optional AByteEncoding input parameter. If it is nil , DefStringEncoding is used. If that is also nil , GIdDefaultTextEncoding is used.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM