dummzeuch 1517 Posted August 1, 2023 (edited) We currently are using TIdTCPClient and TIdTCPServer from Indy10 for communication between applications written in Delphi 2007, so all strings are AnsiStrings. Now I have got the first program that is written in Delphi 10.2, so all strings are now Unicode strings. Is there anything special I need to do so it can communicate with the existing server which is still written in Delphi 2007? Edit: Strings here are only used for text (commands and parameters) not abused as buffer for binary data. Edited August 1, 2023 by dummzeuch Share this post Link to post
DelphiUdIT 187 Posted August 1, 2023 Uses IdGlobal; procedure TForm1.Button1Click(Sender: TObject); var s: ansistring; t: TIdBytes; begin s := AnsiString('ABCD'); t := rawToBytes(s[1], length(s)); IdTCPClient1.IOHandler.Write(t); end; To communicate with older devices, I use ansistrings like that. Share this post Link to post
Remy Lebeau 1436 Posted August 1, 2023 (edited) 1 hour ago, DelphiUdIT said: Uses IdGlobal; procedure TForm1.Button1Click(Sender: TObject); var s: ansistring; t: TIdBytes; begin s := AnsiString('ABCD'); t := rawToBytes(s[1], length(s)); IdTCPClient1.IOHandler.Write(t); end; To communicate with older devices, I use ansistrings like that. You don't need to use RawToBytes() in this case. The TIdIOHandler.Write(string) method has an optional ADestEncoding parameter to specify the byte encoding on the wire, such as UTF-8 (the default is ASCII). You can alternatively use the TIdIOHandler.DefStringEncoding property. And, in pre-Unicode versions, Write() also has an optional ASrcEncoding parameter to specify the byte encoding of the input AnsiString (the default is the user's OS default). Or, you can alternatively use the TIdIOHandler.DefAnsiEncoding property. Edited August 1, 2023 by Remy Lebeau 2 Share this post Link to post
Remy Lebeau 1436 Posted August 1, 2023 (edited) 2 hours ago, dummzeuch said: Is there anything special I need to do so it can communicate with the existing server which is still written in Delphi 2007? If you are using strictly ASCII characters only, then no. All of the default settings should suffice. But, if you are using any non-ASCII characters, then make sure both client and server agree on a common byte encoding on the wire, ie UTF-8. You can use the TIdIOHandler.DefStringEncoding property, or the AByteEncoding parameter on individual read/write methods. Indy will convert Unicode to wire encoding on writes, and from wire encoding to Unicode on reads. In the D2007 code, you should also tell Indy which encoding your AnsiString's are using, if different than the OS default. You can use the TIdIOHandler.DefAnsiEncoding property, or the ADestEncoding/ASrcEncoding parameter on individual read/write methods, respectively. Indy will convert ANSI to Unicode to wire encoding on writes, and from wire encoding to Unicode to ANSI on reads. Edited August 1, 2023 by Remy Lebeau 1 Share this post Link to post
Fr0sT.Brutal 900 Posted August 7, 2023 Anyway, if your server is supportable and updatable, I'd recommend to throw away any ANSI (ACP, Def system codepage etc) stuff and just explicitly use UTF-8 and probably explicit plain ASCII for commands. Share this post Link to post