Sign in Join
Wiki copytemporary

Indy with Lazarus: what changed

Revision 1 to 2. Removed lines have a minus sign; added lines have a plus sign.

OldNewLine
11Indy is an open source client/server communications library that supports TCP/UDP/RAW sockets, as well as over 100 higher level protocols including SMTP, POP3, IMAP, NNTP, HTTP, FTP, and many more
22
33## Indy for Lazarus
44
55A new attempt at converting Indy is being undertaken by the Indy core team. FPC developer Marco van de Voort is working with Indy core to get Indy fully working with FPC/Lazarus. Specially Indy's JP Mugaas did a lot of good work in getting Indy10 to work with FPC. The native unixrtl backend is mostly his work too.
66
77Currently Indy10 is nearly fully working, and end-user usability has been improved a lot. Only special topics like OpenSSL and compression might need additional knowledge. 64-bit support hasn't entirely been validated either.
88
99Hint: I'm not very interested in support the Kylix side of Indy. (anything that uses unit libc). I ported it only as step up to native Unix RTL using Indy apps.
1010
1111### Requirements
1212
1313FPC 2.0.4 is very close to being able to use Indy in all its facets, except for the server bug on FreeBSD/macOS (which requires 2.1.1)
1414
1515Since Indy10 now works for all major targets, we focus on this version. While conversion to Indy9 might be simpler for people, keep in mind that it only works on Win32 (and theoretically could be ported to Linux/x86).
1616
1717Therefore we recommend people to work with 10 as much as possible.
1818
1919(For indy9, you might need to remove the overriding of TMemoryStream.SetSize method (Marcov: ???) to get telnet components working, but Indy9 hasn't been tested in a while).
2020
2121The port is fairly stable, and JP Mugaas has done a great deal to improve the quality of the release, a set of makefiles inclusive.
2222
2323### Downloads / Links
2424
2525Current snapshots (for die hards only) are at
2626
2727- Indy9:
2828 - [Indy9, includes demos](http://www.stack.nl/~marcov/indy/indy9.zip) and
2929- Indy10:
3030 - converted Indy10 demos : [converted Indy10 demos](http://www.stack.nl/~marcov/demo10.zip)
3131 - [Indy 10 website](http://www.indyproject.org) Recently, this archive started to include demos too.
3232
3333### What works, what not
3434
3535**Indy9**:
3636
3737- Windows should largely work. Lots of demos ported.
3838- Linux not or barely. No hope at non Linux/x86 (non-Kylix) targets.
3939
4040**Indy10**:
4141
4242- Windows and Unix: clients work and servers should work fine in principle.
4343- The main work for native Unix RTL done. Servers Clients seem to work with FreeBSD and OS X
4444
4545All: secure versions not tested yet.
4646
4747### Short term plans
4848
4949- Convert demos to demonstrate/test workings.
5050- Fix bugs and enter them back into FPC or Indy RCS.
5151
5252### Problems
5353
5454- Indy9 and Indy10 are mutually exclusive, which causes problems for deployment, even the default is a problem:
5555 - Indy9 is more used and proven in the industry.
5656 - Indy10 is more portable, and better long term. However uptake seems to be low, and there is not much movement at Indy anymore.
5757- How to deploy? Parts belong to Lazarus, parts to FPC.
5858- Lot of pkgs and demos have paths in them. How to centrally fix them so that inexperienced users can build them?
5959- Lazarus problems
6060 - Transparency problems of icons
6161 - component tabs don't scroll, if you put a lot of components in one tab, they are not selectable. **workaround implemented**: JP Mugaas separated them into Indy clients A-M and N-Z etc. Also, meanwhile Lazarus changed to two rows of components per tab.
6262- Indy demos (specially Indy10's) are not very suitable for multiplatform usage. Their setup is awfully windows specific, with spaces in paths, deep nested dirs, and useless baggage (C# code). A short working set of demos will have to be created.
6363
6464### Bugs
6565
6666- Indy10 servers didn't work before due to an exception occurring during startup, which shut everything down. You need FPC 2.2(.0) or later to fix this (pthread_kill problem). This probably also affects Mac OS X.
6767
6868- During demo conversion, the bindings property is often wrongly converted. This can result in strange errors, specially because Indy seems to bind to the same port using both IPV4 and IPV6 at the same time.
6969
7070Ubuntu 10.04 + Lazarus 0.9.28 + Indy 10(Server Component) -\> launch & do nothing (just crash)
7171
7272Solution (bruce0829@yahoo.com.tw collect and organize data):
7373
7474(1).Lazarus Main menu -\> Project -\> Compiler Options -\> Other Page , add the "-dUseCThreads" parameter. (2).force the IdTCPServer to work in Id_IPV4 mode.
7575
7676``` pascal
7777procedure TForm1.FormActivate(Sender: TObject);
7878var
7979 Binding: TIdSocketHandle;
8080begin
8181 //uses idGlobal
8282 //explicitly adding a Binding object prevents TIdTCPServer
8383 //from creating its own default IPv4 and IPv6 Binding objects
8484 //on the same listening IP/Port pair...
8585 Binding := IdTCPServer1.Bindings.Add;
8686 Binding.IPVersion := Id_IPv4; //optional: forces the Binding to work in Id_IPV4 mode.
8787 Binding.IP := '127.0.0.1';
8888 Binding.Port := 6501; //customization
8989 IdTCPServer1.Active := True;
9090end;
9191```
9292
9393(3)use TIdSync to Control your GUI in IdTCPServer's OnExecute() event.
9494
9595## Installation
9696
9797### How to install
9898
9999Comment from RLebeau: Indy is available in [[Online Package Manager]].
100100
101101Comment from Matthijs: So it is not perfect yet, but you want to try it. Here is how you install it in Lazarus.
102102
103103- Open and compile indysystemlaz.lpk
104104- Open and compile indycorelaz.lpk
105105- Open and compile indyprotocolslaz.lpk
106106- Open, compile and install dclindycorelaz.lpk
107107- Open, compile and install dclindyprotocolslaz.lpk
108108
109109Then rebuild Lazarus and you will see a 15 tab's with Indy components.
110110
111111### How to install on Debian/Ubuntu
112112
113113Commands in Terminal:
114114
115-`cd indy-10.2.0.1/fpc`\
116-`chmod +x debian/rules`\
117-`touch README`\
118-`sudo apt-get install fakeroot`\
119-`dpkg-buildpackage -rfakeroot -uc`\
120-`cd ..`\
121-`sudo dpkg -i *.deb`
115+```text
116+cd indy-10.2.0.1/fpc
117+chmod +x debian/rules
118+touch README
119+sudo apt-get install fakeroot
120+dpkg-buildpackage -rfakeroot -uc
121+cd ..
122+sudo dpkg -i *.deb
123+```
122124
123125Then install the package indylaz.lpk in Lazarus.
124126
125127### How to install \[2\]
126128
127129If you couldn't install Indy for Lazarus with tips above, you can try this...
128130
129131From [Yahoo! Brazil, Lazarus Group](http://br.groups.yahoo.com/group/lazarus-brasil/) (User Everaldo)
130132
131133Version installed on Lazarus 0.9.24 using component indy-10.2.0.1.
132134
133135- Unzip the component from file tar.gz (must be this file, the "zip file" does not work) in directory \$(LazarusDir)\components;
134136- Go to directory \$(LazarusDir)\components\indy-10.2.0.1\\ and to create inside them a directory named "saved";
135137- Copy the content of the directory \$(LazarusDir)\components\indy-10.2.0.1\lazarus\\ to directory "saved" created above;
136138- Copy the content of directory \$(LazarusDir)\components\indy-10.2.0.1\fpc\\ to directory \$(LazarusDir)\components\indy-10.2.0.1\lazarus, and rewrite all files, ok;
137139- Get the content of directory "saved" and copy inside of \$(LazarusDir)\components\indy-10.2.0.1\lazarus and you can delete "saved" directory now;
138140- Install the package laz.lpk (available in \$(LazarusDir)\components\indy-10.2.0.1\lazarus\indy) of conventional way.
139141
140142On LINUX the path is: /usr/lib/lazarus/components/indy-10.2.0.1/
141143
142144### How to install on Windows and Debian Linux, Indy 10.5 and above
143145
144146- Need working Lazarus (and FPC) for this
145147- Download from <http://www.indyproject.org/Sockets/Download/DevSnapshot.EN.aspx>. Or from the alternate web site for the updated and current versions: <http://indy.fulgan.com/>
146148- unpack into a directory
147149- copy the *.pas, *.lrs and *.inc of the \Lib\System, \Lib\Core, and \Lib\Protocols subdirectories into a new directory of your choosing
148150- copy the indylaz.lpk in the \Lib directory to the directory you created above
149151- from within Lazarus do a Package -\> Open package file, open the indylaz.lpk
150152- in the Package Options dialog, add the path to the directory you created above to the "Unit" field.
151153- compile then install (will rebuild Lazarus). EDIT: Currently, due to a know bug in FPC, you must compile the Indy package TWICE before installing it.
152154
153155In order to write & compile Indy10 applications, you need to put the path to the Indy directory in the "Other Unit files" textbox of every project that you write. You'll find "Other Unit files" under Project Options -\> Compiler Options -\> Paths.
154156
155157### How to install (confirmed) on Windows - Indy 10.2
156158
157159For a lot of users, I'm sure that the information given above won't work, or will be somewhat confusing given the differences between versions and inconsistent explanations.
158160
159161The website points you to download the latest version from the snapshots page. This wiki tells you to copy a lot of files over into directories. For me, neither worked, and ended up making a mess of my Lazarus installations.
160162
1611631. Firstly, the page I would retrieve this from is [here](http://www.indyproject.org/Sockets/fpc/index.EN.aspx). Other sites I tried had problems with some files inside the archive.
1621642. When you open up the archive above, you will see there are folders: "fpc" and "lazarus".
163165 1. You can copy the contents of "fpc" into: LAZARUS_DIR\fpc\2.6.0\source\packages\indylaz if you want to have things neat and tidy.
164166 2. The "lazarus" folder, you copy into LAZARUS_DIR\components\indylaz
165167 3. With both of these, make sure that there isn't a sub-directory inside the folders given. i.e. LAZARUS_DIR\components\indylaz\lazarus\\
1661683. Go into Lazarus and go to "Package" -\> "Open package file" and point it to the "indylaz.lpk" inside the LAZARUS_DIR\components\indylaz directory.
1671694. Once the package loads inside your project, click on the "options" button, which resembles an image of a parcel with a cog next to it.
1681705. Click the "Compiler Options" on the left-hand side and Click on the ".." button next to "Other unit files (-Fu) (delimiter is semicolon)".
169171
170172Select the "fpc" then "lazarus" folders you created above and click OK. Lazarus will sort out the relative path for you. Don't change it.
171173
1721741. Click OK and compile and then direct angry bile towards the individual who has steered you wrong with the previous, unhelpful, instructions.
173175
174176### Issue on Windows 64 bits
175177
176178On Windows 64 bits, the compilation of the archive mentioned above will not work. This can be fixed by editing IdAntiFreeze.pas, replacing:
177179
178180``` pascal
179181 type
180182 TIdAntiFreeze = class(TIdAntiFreezeBase)
181183 public
182184 procedure Process; override;
183185 end;
184186```
185187
186188by
187189
188190``` pascal
189191 type
190192 TIdAntiFreeze = class(TIdAntiFreezeBase)
191193 public
192194 {$IFDEF WIN32}
193195 procedure Process; override;
194196 {$ENDIF}
195197 end;
196198```
197199
198200## Various tips
199201
200202### Memory leaking issue
201203
202204If you have memory leaks in your Indy application, that is because you use **IdStack** or **IdThread** units, or components that depend on them. It is intended by design, and in Delphi the leak reports are suppressed by registering the leaks with the memory manager. This feature is not available with Free Pascal, but you can remove the deliberate memory leaks. In file **IdCompilerDefines.inc** you should replace this line:
203205
204206``` pascal
205207 {.$DEFINE FREE_ON_FINAL}
206208 {$UNDEF FREE_ON_FINAL}
207209```
208210
209211with this:
210212
211213``` pascal
212214 {$DEFINE FREE_ON_FINAL}
213215 {.$UNDEF FREE_ON_FINAL}
214216```
215217
216218and recompile Lazarus and Indy. Beware that IdCompilerDefines.inc exists in 5 different directories and you need to make changes in all of them.
217219
218220#### Important developer note
219221
220222The leaks are not a matter of not being able to free the objects (obviously, they can be, as seen when FREE_ON_FINAL is defined), but more a matter of unit dependency. The objects in question are shared with other units, and it has been noticed that sometimes units may not always be finalized in the order you are expecting, and that has been observed in the wild. So rather than freeing these objects by default, they are leaked instead, in case they are still accessed later. The leak is minor (only a few bytes), and only during unit finalization, which 9x% of the time will only be during application shutdown (unless you are using Indy in a DLL that gets unloaded dynamically during runtime).
221223
222224### How to use non-blocking TCP sockets
223225
224226Advice from FPC developer Marco van de Voort: Indy can be used nonblocking if you regularly check for data on source:
225227
226228``` pascal
227229 fclient.IOHandler.CheckForDataOnSource(5);
228230```
229231
230232and then never read more than InputBuffer.Size:
231233
232234``` pascal
233235 insiz:= IOHandler.InputBuffer.Size;
234236 IOHandler.ReadStream(strmbuf, insiz, false);
235237```
236238
237239While Indy 10 does a lot with streams (due to its .NET heritage) you can workaround it by using a TCustomMemoryStream derivative that just points to your own buffers, with nearly no overhead.
238240
239241I myself use this for a set of client-servers that do work in threads, but use events to try to reach (relatively) low latency comms.
240242
241243## External links
242244
243245- [The Indy Project official website](http://www.indyproject.org)
244246
245247---
246248*From the Free Pascal wiki, page "Indy with Lazarus", as it stood on 2022-08-09 after a change by Alextp, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*

Back to history