Skip to content
geby edited this page Jan 26, 2024 · 2 revisions

Welcome to the Synapse wiki!

How-to (Synapse basics)

install Synapse

Synapse is NOT a set of components. It is only library of units with code and classes. It cannot be installed, it does not need to be installed! To use Synapse, you simply copy all the necessary Synapse units to your project directory (or to your library search path) and in your project add a USES line listing the needed Synapse units.

The non-component concept is very good for writing non-visual applications, i.e. Windows services, CGI programs, Command-line programs. You may use Synapse in a visual program too. It is easy!

Read Data With Synapse

There does not exist an event for reading data in Synapse. Why? It is not needed! In other libraries you must read data when it comes in to your system with an event. This event is outside of your processing procedure! Then you must parse this data and get what you need! You must synchronise your procedure with these events. It is not practical in most cases!

Synapse is a synchronous library, because you do not need to do this synchronisation. All data read is synchronised with your processing code! You do not need to know when data arrives. This data is silently stored in internal buffers.

You call a read operation when you need read some data. Look, you call read operation when YOU need data, not when the system needs to read data!

When you need to read data, then you need to:

  • read known count of bytes You know how many bytes you need. You can use RecvBuffEx method to receive a specific number of bytes in to your binary buffer. You can use RecvBuffStr too. This function reads bytes in to a binary string. This string is good for a dynamicly allocated binary buffer.
  • read bytes with known terminator You know the sequence which terminates your data block. You can use the RecvTerminated method. A special case is reading lines of text terminated by CRLF. For this you can use special RecvString method. When you use this method and turn on the ConvertLineEnd property, then Synapse autodetects the correct line terminating sequence. It can receive lines terminated by CRLF, LFCR, CR or LF! It is very good for your bug-tolerant application.
  • read any data You simply need to receive any incoming data, regardless of the amount. Then you can use the RecvPacket method.
  • combination of above You can freely combine all the previous methods. You can read one line with length (in text form) of next data block and then you can read this data block with RecvBuffStr, for example.

AnsiString as binary buffer

AnsiStrings can be used for storing binary data Because the length of the string is not determined by searching for char #0 (it is stored outside of the string), you can use all binary data - even #0. These long strings are ideal for binary buffers, because they are automatically allocated and deallocated from memory. By using long strings as binary buffers you can create memory-leak-free applications!

However, you have to be careful when writing your strings to the display because most graphical controls cannot display binary strings (they expect null-terminated strings). Of course, you cannot cast this binary string to a (null-terminated) PChar. And be careful with implicit charset conversions in Unicode based Delphi editions.