Sign in Join
Wiki copytemporary

Code Conversion Guide: what changed

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

OldNewLine
11This page is about how to port or convert existing Delphi or Kylix code to work with the [[Free Pascal]] Compiler and Lazarus IDE. While Lazarus and the Free Pascal Compiler have aspects in common with Delphi and Kylix, they are not clones. There are a number of library call and convention differences... and in some areas, FPC is enhanced and can be more demanding about correct syntax. Please see the [[Lazarus For Delphi Users]] guide for a description of some of the functional differences.
22
33The purpose of this guide is to document some of the specific differences that are frequently encountered during the code conversion process when translating existing code from Delphi to Lazarus.
44
55This document was placed into the wiki knowledge-base area so it could be easily extended by anyone who had encountered a unique problem and would like to post it for others to be aware of.
66
77## Selecting a component or library for conversion
88
99### Where to find code to convert
1010
1111There is a LOT of code available on the net that can be converted for use with FPC and Lazarus. Here is a [[Page Of Code Sites]] that is just a start. Please add to it if you know of any other good locations. TurboPower Software has recently released their entire commercial offering under the MPL. A list of available packages can be found [here](http://sourceforge.net/users/tpsfadmin/).
1212
1313To avoid duplicating effort, packages that have already been converted are listed on the [[Components and Code examples]] page. If you've converted a package or are working on one, please add a note on the [[Current conversion projects]] page.
1414
1515### Licensing
1616
1717Licenses for existing code range from freeware/public domain to restrictive versions that prohibit modification, re-distribution and commercial use. Before converting any package, it's a good idea to examine its licensing and make sure it's going to be compatible with Lazarus and the Free Pascal Compiler. License selection is especially important with components since dropping one on a form can impose an unwanted or incompatible license on an entire application.
1818
1919When converting components, please respect the wishes of the original author and retain all copyright and licensing headers along with email addresses and url's. It's courteous and often useful to inform the author that their component is being converted... especially if the component is under a restrictive license. New interest in an old or forgotten component can sometimes inspire authors to revise their original and overly restrictive licensing.
2020
2121In general, Public Domain (freeware), and the LGPL/MPL are the the most flexible for distributing components. For more information, the [Open Source Definition](http://www.opensource.org/docs/definition.php) is a good place to start. There are also several comparisons available to help clarify how the various types of licenses work and what impact they'll have on code they're linked to. Search for "open source license comparison"
2222
2323### Dependencies
2424
2525Another step before starting to work on a conversion is to verify that the code doesn't have deep dependancies on other packages that might not be available or represent a considerable conversion challenge. Some freeware offerings are bound to or extend proprietary packages that are frequently no longer available or come with inappropriate licenses.
2626
2727### Compiler Issues
2828
2929See:
3030
3131- [Known problems](http://www.freepascal.org/probs.html)
3232- [Unfixed bugs](https://gitlab.com/freepascal.org/fpc/source/-/issues)
3333
3434### Platform and OS Issues
3535
3636Lazarus and the Free Pascal Compiler are cross-platform and cross-architecture development tools. In contrast, most existing Delphi code was specifically designed to run on an Intel processor under Win32. If your candidate component has a lot of Win32 specific code, it might be wise to try and find a less platform dependant alternative. But don't let this stop you... it's genuinely amazing what the LCL supports!
3737
3838## Doing the conversion
3939
4040### Setting up the Lazarus environment for a conversion project
4141
4242#### Create a test project
4343
4444- Place code to be converted into a subdirectory (ie: convertdir)
4545- Bring up Lazarus
4646- File-\>Save All to the convertdir subdirectory. Meaningful names for the Project and default unit are optional.
4747- Open the "main" unit to be converted in convertdir
4848- Add it to the project: Project-\>Add Active Unit to Project
4949- Run Tools-\>Quick Syntax Check or Run Build All to get started.
5050
5151#### Delphi VCL, Kylix CLX Sources in Lazarus
5252
5353When converting Delphi/Kylix sources, it is often useful to do a find declaration to see, what a specific function is doing. The Lazarus IDE can parse the Delphi/Kylix sources. To do this it needs some searchpaths and compiler settings. You can easily setup this in Environment-\>CodeTools Defines Editor-\>Insert Template
5454
5555### Conversion problems and solutions
5656
5757#### Delphi / Kylix file equivalents in Lazarus
5858
59-<table>
60-<thead>
61-<tr>
62-<th><p>Delphi / Kylix</p></th>
63-<th><p>Description</p></th>
64-<th><p>Lazarus</p></th>
65-<th><p>Description</p></th>
66-</tr>
67-</thead>
68-<tbody>
69-<tr>
70-<td data-valign="top"><p>.pas</p>
71-<p>.dfm/.xfm,</p>
72-<p>.dcu/.dpu,</p>
73-<p>.dpr(main project file),</p>
74-<p>.res,</p>
75-<p>.dof/.kof</p>
76-<p>---</p>
77-<p>---</p>
78-<p>---</p></td>
79-<td data-valign="top"><p>Delphi Source File, Delphi Form,</p>
80-<p>Delphi Compiled Unit,</p>
81-<p>Delphi Project,</p>
82-<p>Windows Resource File,</p>
83-<p>Delphi Option File</p></td>
84-<td data-valign="top"><p>.pas, .pp .lfm,</p>
85-<p>.o,</p>
86-<p>.lpr</p>
87-<p>---</p>
88-<p>---</p>
89-<p>.lrs,</p>
90-<p>.lpi(main project file),</p>
91-<p>.ppu</p></td>
92-<td data-valign="top"><p>Pascal unit file,</p>
93-<p>Form data file,</p>
94-<p>Compiled unit file,</p>
95-<p>Project file,</p>
96-<p>Resource file,</p>
97-<p>Project options file,</p>
98-<p>Lazarus resource file,</p>
99-<p>Lazarus project information file,</p>
100-<p>FPC unit description file</p></td>
101-</tr>
102-</tbody>
103-</table>
59+**Delphi / Kylix**
10460
61+**Description**
62+
63+**Lazarus**
64+
65+**Description**
66+
67+.pas
68+
69+.dfm/.xfm,
70+
71+.dcu/.dpu,
72+
73+.dpr(main project file),
74+
75+.res,
76+
77+.dof/.kof
78+
79+---
80+
81+---
82+
83+---
84+
85+Delphi Source File, Delphi Form,
86+
87+Delphi Compiled Unit,
88+
89+Delphi Project,
90+
91+Windows Resource File,
92+
93+Delphi Option File
94+
95+.pas, .pp .lfm,
96+
97+.o,
98+
99+.lpr
100+
101+---
102+
103+---
104+
105+.lrs,
106+
107+.lpi(main project file),
108+
109+.ppu
110+
111+Pascal unit file,
112+
113+Form data file,
114+
115+Compiled unit file,
116+
117+Project file,
118+
119+Resource file,
120+
121+Project options file,
122+
123+Lazarus resource file,
124+
125+Lazarus project information file,
126+
127+FPC unit description file
128+
105129So a Delphi .dcu file roughly corresponds to a FPC .o and .ppu together in one file. The .PPU is mostly the header(interface) part, the .o mostly the implementation part. Main exceptions are inlined functions, that in to-be-inlined form are in the .ppu.
106130
107131#### Converting Delphi projects/forms/units to Lazarus
108132
109133Use the Delphi converter in new Lazarus version to convert automatically. It does most of the things explained later on this page. More information here: [[Delphi Converter in Lazarus]]
110134
111135The following text explains the differences between Delphi and Lazarus and how to convert manually.
112136
113137#### Selecting the right compiler mode
114138
115139The [[Free Pascal]] Compiler supports 5 different pascal modes. For example TP for turbo pascal, lets you compile turbo pascal units. There is also a DELPHI compatibility mode that can be set to make existing code easier to convert. Lazarus prefers the OBJFPC mode, which almost equals the DELPHI mode, but is less ambiguous than the Delphi syntax. Here are the important points:
116140
117141The mode can be selected at command line or at the start of the source. Using the command line has the advantage, that you don't need to change the source, but the disadvantage, that others must be told.
118142
119143Most Delphi units can be compiled by the [[Free Pascal]] compiler by adding:
120144
121145``` pascal
122146{$IFDEF FPC}
123147 {$MODE DELPHI}
124148{$ENDIF}
125149```
126150
127151right after the unit name.
128152
129153For more details about [[Free Pascal]] modes see the [Free Pascal Documentation](http://www.freepascal.org/docs-html/prog/progap4.html#progse62.html)
130154
131155#### Cross-Platform considerations
132156
133157- Inline assembler is always a problem because it will bind the code to the Intel architecture. Some developers do algorithm prototypes in Pascal and ifdef the their optimized assembler. Fortunately TurboPower did this in numerous places with their code. If this is the case with the package you're converting, throw the switch back to Pascal.
134158- Don't reference specific memory location like the BIOS data area. Find out what the code needs and try to find a cross platform alternative.
135159- Don't do processor specific tricks (like using the Intel TSC) without enclosing your code in an ifdef for the platform the code needs... and providing an alternative for environments that don't have the hardware capability.
136160- If you need some OS specific code, then you can use IFDEFs. See below for a list of macros.
137161
138162#### Useful compiler variables / defines / macros
139163
140164To write code, that behaves on different systems differently, you can use the
141165
142-<div class="dir">
143-
144166{\$IFDEF Name}
145167
146-</div>
147-
148168directives.
149169
150-- <div class="dir">
151-
152- {\$IfDef FPC}
153-
154- </div>
170+- {\$IfDef FPC}
155171
156172This variable is defined, when using the FPC compiler. Useful to write code, that works with FPC and Delphi. For compatibility reasons FPC defines the DELPHI macro in mode Delphi. So you can **not use {\$IFNDEF DELPHI}**.
157173
158-- <div class="dir">
159-
160- {\$IfDef FPC_OBJFPC}
161-
162- </div>
174+- {\$IfDef FPC_OBJFPC}
163175
164176This variable is defined when using mode OBJFPC and can be a substitute for {\$IFNDEF Delphi} for e.g. the @ differences
165177
166-- <div class="dir">
167-
168- {\$IfDef LCL}
169-
170- </div>
178+- {\$IfDef LCL}
171179
172180This variable is defined, when using the LCL package. Useful to write code, that works with the LCL and Delphi.
173181
174-- <div class="dir">
175-
176- {\$IfDef LCLGtk}
177-
178- </div>
182+- {\$IfDef LCLGtk}
179183
180184 ,
181185
182- <div class="dir">
183-
184186 {\$IfDef LCLWin32}
185187
186- </div>
187-
188188 ,
189189
190- <div class="dir">
191-
192190 {\$IfDef LCLQt}
193191
194- </div>
195-
196192 , ...
197193
198194This variable is defined, when using the LCL package and the specific [[Widgetset|widgetset]] is currently used. Useful to write code, that works with the LCL on a specific platform.
199195
200-- <div class="dir">
201-
202- {\$IfDef Unix} // for Linux, BSD, macOS, Solaris
203-
204- </div>
196+- {\$IfDef Unix} // for Linux, BSD, macOS, Solaris
205197
206198 ,
207199
208- <div class="dir">
209-
210200 {\$IfDef Win32}
211201
212- </div>
213-
214202 ,
215203
216- <div class="dir">
217-
218204 {\$IfDef Linux}
219205
220- </div>
221-
222206 // for Linux,
223207
224- <div class="dir">
225-
226208 {\$IfDef Darwin}
227209
228- </div>
229-
230210 // macOS,
231211
232- <div class="dir">
233-
234212 {\$IfDef WinCE}
235213
236- </div>
237-
238214 // for WinCE,...
239215
240216Defined by FPC for the current Target OS. Delphi defines "Linux", "Win32" and "MSWindows". [[Free Pascal]] runs on much more platforms and so it is recommended to use the more general items. For example "Unix" is defined for Linux, FreeBSD, NetBSD and OpenBSD, where Lazarus already runs. Use for code that should work with Delphi and FPC:
241217
242218``` pascal
243219{$IFDEF Linux}
244220 {$DEFINE Unix}
245221{$ENDIF}
246222```
247223
248224to work around this for Kylix.
249225
250-- <div class="dir">
251-
252- {\$IfDef ENDIAN_BIG}
253-
254- </div>
226+- {\$IfDef ENDIAN_BIG}
255227
256228This macro is defined on big endian processors such as the PowerPC as used, a.o., in older Apple computers. Their byte order is the reverse of that of Intel compatible processors.
257229
258-- <div class="dir">
259-
260- {\$IfDef ENDIAN_BIG}
261-
262- </div>
230+- {\$IfDef ENDIAN_BIG}
263231
264232For more details see the [Free Pascal Documentation](http://www.freepascal.org/docs-html/prog/prog.html#QQ2-23-21).
265233
266234#### 32bit / 64 bit support
267235
268236Pointers under 64bit need 8 bytes instead of 4 on 32bit. The 'Integer' type remains for compatibility 32bit. This means you can no longer typecast pointers into integers and back. FPC defines two new types: PtrInt and PtrUInt. PtrInt is a 32bit signed integer on 32 bit platforms and a 64bit signed integer on 64bit platforms. The same for PtrUInt, but *unsigned* integer instead. Use for code that should work with Delphi and FPC:
269237
270238``` pascal
271239{$IFNDEF FPC}
272240type
273241 PtrInt = integer;
274242 PtrUInt = cardinal;
275243{$ENDIF}
276244```
277245
278246Replace all **integer(SomePointerOrObject)** with **PtrInt(SomePointerOrObject)**.
279247
280248For more information see [[Multiplatform Programming Guide]].
281249
282250#### Finding a missing identifier
283251
284252There are differences in how the LCL is organized when compared to the Delphi VCL. If you get a "not found" compiler error about a major class or identifier, the chances are good that it's in a different unit. A complete cross reference can be found by grep'ing lazarus/docs/xml or the lcl subdirectory.
285253
286254For example the commonly used tbutton typically throws an error in Delphi code because it's located in a unit named buttons.pp. The following command finds the correct unit very quickly (in the lazarus source directory):
287255
288256``` bash
289257grep -in ' tbutton =' lcl/*
290258```
291259
292260#### Major unit differences between Lazarus and Delphi
293261
294262**Please add to this topic!**
295263
296264- Windows-\>Interfaces, LCLIntf, LCLType, LCLProc, ...)
297265
298266As the LCL is not windows specific, the code that is in the Delphi Windows unit for directly accessing the Win32 API is abstracted into separate interfaces, which can be accessed from the LCLIntf unit. Keep in mind, that Lazarus does not emulate win32, so many functions are missing and some do not work as their win32 counterparts. These functions only exist for Delphi compatibility and should only be used for quick & dirty porting. LCL also breaks out many of the types, so often LCLType is required. LCLProc also contains a few functions which can be useful for lower level handling such as "FreeThenNil" as is in Delphi 5 and higher, "DeleteAmpersands" to remove additional ampersands from a string for controls(& vs && etc). The Interfaces unit needs to be included in the .lpr file to initialize the appropriate widgetset.
299267
300268- Messages-\>LMessages
301269
302270TControl Messages for win32 event callbacks of the format WM_CALLBACK and the structs associated with them are often found in the Messages unit in Delphi. In the LCL these types of messages and there structs are usually found in LMessages, usually with name changes of WM to LM, so for instance WM_MOUSEENTER becomes LM_MOUSEENTER, and TWMMouse becomes TLMMouse.
303271
304272- Graphics, Controls-\>GraphType, GraphMath, Graphics, Controls
305273
306274To simplify some things and break complexity of circles between units, a few types have been abstracted into a shared unit called GraphType, which includes things, which in Delphi are located in Graphics or Controls, for instance the bvNone etc of panels. So sometimes you have to include it. Also a unit which, although incompatible with Delphi, adds other useful functionality is GraphMath, which adds a TFloatPoint for precision, misc routines for dealing with beziers, lines, and arcs, as well as some operator overloading for use with TPoints and TRect, such as for instance Point1 := Point2 + Point3, and comparing two rects like if (rect1 = rect2) then ...
307275
308276- Mask-\>MaskEdit
309277
310278For more intelligent naming considerations, the unit for TMaskEdit is called \[MaskEdit\|\] instead of the slightly more nebulous Mask as in many versions of Delphi.
311279
312280- StdCtrls-\>StdCtrls,Buttons
313281
314282In many version of Delphi TButton is located in StdCtrls, while TSpeedButton and TBitBtn are in Buttons. For consistency and simplicity the LCL puts all button types in Buttons, which can occasionally break code conversion, so it is always a good idea to include.
315283
316284#### Property and method differences Delphi -\> FPC/LCL
317285
318286- TBitmap contains a canvas in the LCL
319287- [[Lazarus Faq|Lazarus_Faq#Why are TForm.ClientWidth.2FClientHeight the same as TForm.Width.2FHeight]]
320288
321289#### Semantical differences
322290
323291##### Order of parameter evaluation
324292
325293Delphi guarantees that all parameters are evaluated from left to right. FPC makes no such guarantee, and can evaluate parameters in any order it wants in order to generate optimal code.
326294
327295##### Nested procedures/functions as procedural variables
328296
329297Delphi passes the framepointer of the parent procedure always on the stack, and has the caller remove it again. This means that as long as you do not access variables from a parent procedure, you can pass the address of a nested function to another function which then can call it like any other procedural variable.
330298
331299FPC on the other hand always passes the framepointer of the parent procedure as a hidden first parameter according to the current calling convention, which means that if you call a nested procedure like a regular procedural variable, all parameters will be "shifted" one position.
332300
333301In short, do not call nested procedures via procedural variables.
334302
335303##### Ref count release
336304
337305Documented behaviour in both Delphi and FPC is that temporary variables stay allocated till after the statement of last use. (so if an interface is used in a parameter declaration, it is earliest released after that whole procedure/method call statement has finished).
338306
339307However in practice FPC often indeed decreases the refcount the very next statement, while Delphi tends to wait till the end of procedures. Or, in very large procedures, till the end of a large block.
340308
341309Both are valid choices though, and fixating this behaviour would hem in the codegeneration and optimizer too much, and it won't changed.
342310
343311This can occasionally cause apparently working Delphi code that mixes object and interface references to fail, and is a typical case of seemingly working code not being correct and depending on implementation choices. The Delphi documentation doesn't make any such guarantees.
344312
345313#### Syntax differences
346314
347315**Please add to this topic!**
348316
349317Because of the inherent strictness in FPC, some syntax changes are necessary, even though
350318
351-<div class="dir">
352-
353319{\$Mode Delphi}
354320
355-</div>
356-
357321does allow more laziness like Delphi does. For this reason complying as much with the syntax rules of
358322
359-<div class="dir">
360-
361323{\$Mode ObjFPC}
362324
363-</div>
364-
365325as possible is highly recommended, even when the codebase is still going to be shared between Delphi and the LCL. Some of these are simply better coding practices, and sometimes because Delphi mode is not entirely accurate, or in a few instances Delphi acceptible code does not function as expected with FPC, even though it might compile. To that end even though not all such are strictly required, the following list of changes should be considered mandatory :
366326
367327##### When assigning an event handling entry point, prefix it with an "@"
368328
369329For instance, you might assign a button [[callback]] manually.
370330
371331`With the Delphi code compiled under Lazarus You will get the error message`\
372332`"Wrong number of parameters specified for call to "SomeFunction" "`
373333
374-<table>
375-<thead>
376-<tr>
377-<th><p>Delphi</p></th>
378-<th><p>OBJFPC</p></th>
379-<th><p>both</p></th>
380-</tr>
381-</thead>
382-<tbody>
383-<tr>
384-<td><div class="sourceCode" id="cb1"><pre class="sourceCode pascal"><code class="sourceCode pascal"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a><span class="kw">begin</span></span>
385-<span id="cb1-2"><a href="#cb1-2" aria-hidden="true" tabindex="-1"></a> <span class="kw">if</span> <span class="kw">not</span> Assigned(MyButton.OnClick) <span class="kw">then</span> </span>
386-<span id="cb1-3"><a href="#cb1-3" aria-hidden="true" tabindex="-1"></a> MyButton.OnClick:= SomeFunction;</span>
387-<span id="cb1-4"><a href="#cb1-4" aria-hidden="true" tabindex="-1"></a> <span class="co">//@ not required</span></span>
388-<span id="cb1-5"><a href="#cb1-5" aria-hidden="true" tabindex="-1"></a> <span class="co">//more code...</span></span>
389-<span id="cb1-6"><a href="#cb1-6" aria-hidden="true" tabindex="-1"></a><span class="kw">end</span>;</span></code></pre></div></td>
390-<td><div class="sourceCode" id="cb2"><pre class="sourceCode pascal"><code class="sourceCode pascal"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true" tabindex="-1"></a><span class="kw">begin</span></span>
391-<span id="cb2-2"><a href="#cb2-2" aria-hidden="true" tabindex="-1"></a> <span class="kw">if</span> <span class="kw">not</span> Assigned(MyButton.OnClick) <span class="kw">then</span></span>
392-<span id="cb2-3"><a href="#cb2-3" aria-hidden="true" tabindex="-1"></a> MyButton.OnClick:= @SomeFunction;</span>
393-<span id="cb2-4"><a href="#cb2-4" aria-hidden="true" tabindex="-1"></a> <span class="co">//@ IS required</span></span>
394-<span id="cb2-5"><a href="#cb2-5" aria-hidden="true" tabindex="-1"></a> <span class="co">//more code...</span></span>
395-<span id="cb2-6"><a href="#cb2-6" aria-hidden="true" tabindex="-1"></a><span class="kw">end</span>;</span></code></pre></div></td>
396-<td><p>|</p>
397-<div class="sourceCode" id="cb3"><pre class="sourceCode pascal"><code class="sourceCode pascal"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a><span class="kw">begin</span></span>
398-<span id="cb3-2"><a href="#cb3-2" aria-hidden="true" tabindex="-1"></a> <span class="kw">if</span> <span class="kw">not</span> Assigned(MyButton.OnClick) <span class="kw">then</span></span>
399-<span id="cb3-3"><a href="#cb3-3" aria-hidden="true" tabindex="-1"></a> MyButton.OnClick:= <span class="ot">{$IFDEF FPC_OBJFPC}</span>@<span class="ot">{$ENDIF}</span>SomeFunction;</span>
400-<span id="cb3-4"><a href="#cb3-4" aria-hidden="true" tabindex="-1"></a> <span class="co">//@ is only required under mode OBJFPC - but not allowed under Delphi</span></span>
401-<span id="cb3-5"><a href="#cb3-5" aria-hidden="true" tabindex="-1"></a> <span class="co">//more code...</span></span>
402-<span id="cb3-6"><a href="#cb3-6" aria-hidden="true" tabindex="-1"></a><span class="kw">end</span>;</span></code></pre></div></td>
403-</tr>
404-</tbody>
405-</table>
334+**Delphi**
406335
336+**OBJFPC**
337+
338+**both**
339+
340+``` pascal
341+begin
342+ if not Assigned(MyButton.OnClick) then
343+ MyButton.OnClick:= SomeFunction;
344+ //@ not required
345+ //more code...
346+end;
347+```
348+
349+``` pascal
350+begin
351+ if not Assigned(MyButton.OnClick) then
352+ MyButton.OnClick:= @SomeFunction;
353+ //@ IS required
354+ //more code...
355+end;
356+```
357+
358+\|
359+
360+``` pascal
361+begin
362+ if not Assigned(MyButton.OnClick) then
363+ MyButton.OnClick:= {$IFDEF FPC_OBJFPC}@{$ENDIF}SomeFunction;
364+ //@ is only required under mode OBJFPC - but not allowed under Delphi
365+ //more code...
366+end;
367+```
368+
407369Note that this behavior of the compiler can also be influenced using the CLASSICPROCVARS modeswitch.
408370
409371##### When calling a procedure variable use this syntax: theprocname()
410372
411373In Delphi there is no difference between a function result and a variable, however there is in FPC, so to call a function, even if it has no parameters, you must append parenthesis.
412374
413375`With the Delphi code compiled under Lazarus You will get the error message`\
414376`"Incompatible types: got "<procedure variable type of function:DWord;StdCall>" expected "LongWord" "`
415377
416-<table>
417-<thead>
418-<tr>
419-<th><p>Delphi</p></th>
420-<th><p>OBJFPC</p></th>
421-<th><p>both</p></th>
422-</tr>
423-</thead>
424-<tbody>
425-<tr>
426-<td><div class="sourceCode" id="cb1"><pre class="sourceCode pascal"><code class="sourceCode pascal"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a><span class="kw">With</span> (SomeObject) <span class="kw">do</span> </span>
427-<span id="cb1-2"><a href="#cb1-2" aria-hidden="true" tabindex="-1"></a><span class="kw">begin</span></span>
428-<span id="cb1-3"><a href="#cb1-3" aria-hidden="true" tabindex="-1"></a> <span class="kw">If</span> Assigned(OnMyCallback) <span class="kw">then</span></span>
429-<span id="cb1-4"><a href="#cb1-4" aria-hidden="true" tabindex="-1"></a> OnMyCallback;</span>
430-<span id="cb1-5"><a href="#cb1-5" aria-hidden="true" tabindex="-1"></a> <span class="co">//parenthesis not required</span></span>
431-<span id="cb1-6"><a href="#cb1-6" aria-hidden="true" tabindex="-1"></a><span class="kw">end</span>;</span></code></pre></div></td>
432-<td><div class="sourceCode" id="cb2"><pre class="sourceCode pascal"><code class="sourceCode pascal"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true" tabindex="-1"></a><span class="kw">With</span> (SomeObject) <span class="kw">do</span> </span>
433-<span id="cb2-2"><a href="#cb2-2" aria-hidden="true" tabindex="-1"></a><span class="kw">begin</span></span>
434-<span id="cb2-3"><a href="#cb2-3" aria-hidden="true" tabindex="-1"></a> <span class="kw">If</span> Assigned(OnMyCallback) <span class="kw">then</span></span>
435-<span id="cb2-4"><a href="#cb2-4" aria-hidden="true" tabindex="-1"></a> OnMyCallback();</span>
436-<span id="cb2-5"><a href="#cb2-5" aria-hidden="true" tabindex="-1"></a> <span class="co">//parenthesis required</span></span>
437-<span id="cb2-6"><a href="#cb2-6" aria-hidden="true" tabindex="-1"></a><span class="kw">end</span>;</span></code></pre></div></td>
438-<td><p>|</p>
439-<div class="sourceCode" id="cb3"><pre class="sourceCode pascal"><code class="sourceCode pascal"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a>Simply use the OBJFPC way, <span class="kw">with</span> brackets:</span>
440-<span id="cb3-2"><a href="#cb3-2" aria-hidden="true" tabindex="-1"></a></span>
441-<span id="cb3-3"><a href="#cb3-3" aria-hidden="true" tabindex="-1"></a> OnMyCallback();</span>
442-<span id="cb3-4"><a href="#cb3-4" aria-hidden="true" tabindex="-1"></a></span>
443-<span id="cb3-5"><a href="#cb3-5" aria-hidden="true" tabindex="-1"></a>Delphi accepts this, too.</span></code></pre></div></td>
444-</tr>
445-</tbody>
446-</table>
378+**Delphi**
447379
380+**OBJFPC**
381+
382+**both**
383+
384+``` pascal
385+With (SomeObject) do
386+begin
387+ If Assigned(OnMyCallback) then
388+ OnMyCallback;
389+ //parenthesis not required
390+end;
391+```
392+
393+``` pascal
394+With (SomeObject) do
395+begin
396+ If Assigned(OnMyCallback) then
397+ OnMyCallback();
398+ //parenthesis required
399+end;
400+```
401+
402+\|
403+
404+``` pascal
405+Simply use the OBJFPC way, with brackets:
406+
407+ OnMyCallback();
408+
409+Delphi accepts this, too.
410+```
411+
448412##### When accessing values in a pointer to a record you must dereference first
449413
450414In Delphi it is not required to de-reference a pointer to a record to access values within it, it can, in fact, be treated just like the record itself, or any other object. In FPC it must be first de-referenced.
451415
452416`With the Delphi code compiled under Lazarus You will get the following messages :`\
453417`"Error: Illegal qualifier"`\
454418`"Hint: may be pointer dereference is missing"`
455419
456-<table>
457-<thead>
458-<tr>
459-<th><p>Delphi</p></th>
460-<th><p>OBJFPC</p></th>
461-<th><p>both</p></th>
462-</tr>
463-</thead>
464-<tbody>
465-<tr>
466-<td><div class="sourceCode" id="cb1"><pre class="sourceCode pascal"><code class="sourceCode pascal"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a><span class="kw">Function</span> GetSomeValue(ARecord: PMyRecord):<span class="dt">Integer</span>;</span>
467-<span id="cb1-2"><a href="#cb1-2" aria-hidden="true" tabindex="-1"></a><span class="kw">begin</span></span>
468-<span id="cb1-3"><a href="#cb1-3" aria-hidden="true" tabindex="-1"></a> <span class="kw">If</span> Assigned(ARecord) <span class="kw">then</span></span>
469-<span id="cb1-4"><a href="#cb1-4" aria-hidden="true" tabindex="-1"></a> Result:=ARecord.SomeValue</span>
470-<span id="cb1-5"><a href="#cb1-5" aria-hidden="true" tabindex="-1"></a> <span class="kw">else</span></span>
471-<span id="cb1-6"><a href="#cb1-6" aria-hidden="true" tabindex="-1"></a> Result:=<span class="dv">0</span>;</span>
472-<span id="cb1-7"><a href="#cb1-7" aria-hidden="true" tabindex="-1"></a><span class="kw">end</span>;</span></code></pre></div></td>
473-<td><div class="sourceCode" id="cb2"><pre class="sourceCode pascal"><code class="sourceCode pascal"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true" tabindex="-1"></a><span class="kw">Function</span> GetSomeValue(ARecord: PMyRecord):<span class="dt">Integer</span>;</span>
474-<span id="cb2-2"><a href="#cb2-2" aria-hidden="true" tabindex="-1"></a><span class="kw">begin</span></span>
475-<span id="cb2-3"><a href="#cb2-3" aria-hidden="true" tabindex="-1"></a> <span class="kw">If</span> Assigned(ARecord) <span class="kw">then</span></span>
476-<span id="cb2-4"><a href="#cb2-4" aria-hidden="true" tabindex="-1"></a> Result:=ARecord^.SomeValue</span>
477-<span id="cb2-5"><a href="#cb2-5" aria-hidden="true" tabindex="-1"></a> <span class="kw">else</span></span>
478-<span id="cb2-6"><a href="#cb2-6" aria-hidden="true" tabindex="-1"></a> Result:=<span class="dv">0</span>;</span>
479-<span id="cb2-7"><a href="#cb2-7" aria-hidden="true" tabindex="-1"></a><span class="kw">end</span>;</span></code></pre></div></td>
480-<td><p>|</p>
481-<div class="sourceCode" id="cb3"><pre class="sourceCode pascal"><code class="sourceCode pascal"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a>Simply use the OBJFPC way, <span class="kw">with</span> ^ :</span>
482-<span id="cb3-2"><a href="#cb3-2" aria-hidden="true" tabindex="-1"></a></span>
483-<span id="cb3-3"><a href="#cb3-3" aria-hidden="true" tabindex="-1"></a> Result:=ARecord^.SomeValue</span>
484-<span id="cb3-4"><a href="#cb3-4" aria-hidden="true" tabindex="-1"></a></span>
485-<span id="cb3-5"><a href="#cb3-5" aria-hidden="true" tabindex="-1"></a>Delphi accepts this, too.</span></code></pre></div></td>
486-</tr>
487-</tbody>
488-</table>
420+**Delphi**
489421
422+**OBJFPC**
423+
424+**both**
425+
426+``` pascal
427+Function GetSomeValue(ARecord: PMyRecord):Integer;
428+begin
429+ If Assigned(ARecord) then
430+ Result:=ARecord.SomeValue
431+ else
432+ Result:=0;
433+end;
434+```
435+
436+``` pascal
437+Function GetSomeValue(ARecord: PMyRecord):Integer;
438+begin
439+ If Assigned(ARecord) then
440+ Result:=ARecord^.SomeValue
441+ else
442+ Result:=0;
443+end;
444+```
445+
446+\|
447+
448+``` pascal
449+Simply use the OBJFPC way, with ^ :
450+
451+ Result:=ARecord^.SomeValue
452+
453+Delphi accepts this, too.
454+```
455+
490456Note that the behavior of the compiler with regards to (auto) de-referencing pointers can also be influenced using the AUTODEREF modeswitch.
491457
492458##### When accessing chars of an indexed string Property of an object, it must be enclosed in parentheses
493459
494460With Delphi it is possible to treat a Property exactly like some other const or var, e.g. even up to accessing individual chars of a string directly, while this is not always possible in FPC, specifically for indexed properties. Instead it must be enclosed in parentheses, to make distinct. While this may not always hold true it is probably a good practice to consider anyway. For example
495461
496-<table>
497-<thead>
498-<tr>
499-<th><p>Delphi</p></th>
500-<th><p>OBJFPC</p></th>
501-</tr>
502-</thead>
503-<tbody>
504-<tr>
505-<td><div class="sourceCode" id="cb1"><pre class="sourceCode pascal"><code class="sourceCode pascal"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a><span class="kw">Type</span> TSomeComponent=<span class="kw">class</span>(TComponent)</span>
506-<span id="cb1-2"><a href="#cb1-2" aria-hidden="true" tabindex="-1"></a> <span class="co">//More code...</span></span>
507-<span id="cb1-3"><a href="#cb1-3" aria-hidden="true" tabindex="-1"></a><span class="kw">Published</span></span>
508-<span id="cb1-4"><a href="#cb1-4" aria-hidden="true" tabindex="-1"></a><span class="kw">Property</span> MyString:<span class="dt">String</span> index <span class="dv">3</span> <span class="kw">read</span> GetMyString;</span>
509-<span id="cb1-5"><a href="#cb1-5" aria-hidden="true" tabindex="-1"></a><span class="co">//More code...</span></span>
510-<span id="cb1-6"><a href="#cb1-6" aria-hidden="true" tabindex="-1"></a><span class="kw">End</span>;</span>
511-<span id="cb1-7"><a href="#cb1-7" aria-hidden="true" tabindex="-1"></a></span>
512-<span id="cb1-8"><a href="#cb1-8" aria-hidden="true" tabindex="-1"></a><span class="kw">var</span></span>
513-<span id="cb1-9"><a href="#cb1-9" aria-hidden="true" tabindex="-1"></a> MyChar:<span class="dt">char</span>;</span>
514-<span id="cb1-10"><a href="#cb1-10" aria-hidden="true" tabindex="-1"></a><span class="kw">begin</span></span>
515-<span id="cb1-11"><a href="#cb1-11" aria-hidden="true" tabindex="-1"></a> <span class="kw">If</span> Length(MyString)&gt;<span class="dv">2</span> <span class="kw">then</span></span>
516-<span id="cb1-12"><a href="#cb1-12" aria-hidden="true" tabindex="-1"></a> <span class="co">//no parenthesis needed</span></span>
517-<span id="cb1-13"><a href="#cb1-13" aria-hidden="true" tabindex="-1"></a> MyChar:= MyString[<span class="dv">3</span>];</span>
518-<span id="cb1-14"><a href="#cb1-14" aria-hidden="true" tabindex="-1"></a> <span class="co">//More code...</span></span>
519-<span id="cb1-15"><a href="#cb1-15" aria-hidden="true" tabindex="-1"></a><span class="kw">end</span>;</span></code></pre></div></td>
520-<td><div class="sourceCode" id="cb2"><pre class="sourceCode pascal"><code class="sourceCode pascal"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true" tabindex="-1"></a><span class="kw">Type</span> TSomeComponent=<span class="kw">class</span>(TComponent)</span>
521-<span id="cb2-2"><a href="#cb2-2" aria-hidden="true" tabindex="-1"></a><span class="co">//More code...</span></span>
522-<span id="cb2-3"><a href="#cb2-3" aria-hidden="true" tabindex="-1"></a><span class="kw">Published</span></span>
523-<span id="cb2-4"><a href="#cb2-4" aria-hidden="true" tabindex="-1"></a><span class="kw">Property</span> MyString:<span class="dt">String</span> index <span class="dv">3</span> <span class="kw">read</span> GetMyString;</span>
524-<span id="cb2-5"><a href="#cb2-5" aria-hidden="true" tabindex="-1"></a><span class="co">//More code...</span></span>
525-<span id="cb2-6"><a href="#cb2-6" aria-hidden="true" tabindex="-1"></a><span class="kw">End</span>;</span>
526-<span id="cb2-7"><a href="#cb2-7" aria-hidden="true" tabindex="-1"></a></span>
527-<span id="cb2-8"><a href="#cb2-8" aria-hidden="true" tabindex="-1"></a><span class="kw">var</span></span>
528-<span id="cb2-9"><a href="#cb2-9" aria-hidden="true" tabindex="-1"></a> MyChar:<span class="dt">char</span>;</span>
529-<span id="cb2-10"><a href="#cb2-10" aria-hidden="true" tabindex="-1"></a><span class="kw">begin</span></span>
530-<span id="cb2-11"><a href="#cb2-11" aria-hidden="true" tabindex="-1"></a> <span class="kw">If</span> Length(MyString)&gt;<span class="dv">2</span> <span class="kw">then</span></span>
531-<span id="cb2-12"><a href="#cb2-12" aria-hidden="true" tabindex="-1"></a> <span class="co">//parenthesis sometimes needed</span></span>
532-<span id="cb2-13"><a href="#cb2-13" aria-hidden="true" tabindex="-1"></a> MyChar:= (MyString)[<span class="dv">3</span>];</span>
533-<span id="cb2-14"><a href="#cb2-14" aria-hidden="true" tabindex="-1"></a> <span class="co">//More code...</span></span>
534-<span id="cb2-15"><a href="#cb2-15" aria-hidden="true" tabindex="-1"></a><span class="kw">end</span>;</span></code></pre></div></td>
535-</tr>
536-</tbody>
537-</table>
462+**Delphi**
538463
464+**OBJFPC**
465+
466+``` pascal
467+Type TSomeComponent=class(TComponent)
468+ //More code...
469+Published
470+Property MyString:String index 3 read GetMyString;
471+//More code...
472+End;
473+
474+var
475+ MyChar:char;
476+begin
477+ If Length(MyString)>2 then
478+ //no parenthesis needed
479+ MyChar:= MyString[3];
480+ //More code...
481+end;
482+```
483+
484+``` pascal
485+Type TSomeComponent=class(TComponent)
486+//More code...
487+Published
488+Property MyString:String index 3 read GetMyString;
489+//More code...
490+End;
491+
492+var
493+ MyChar:char;
494+begin
495+ If Length(MyString)>2 then
496+ //parenthesis sometimes needed
497+ MyChar:= (MyString)[3];
498+ //More code...
499+end;
500+```
501+
539502##### You must typecast pointers to actual type when using with var or function of that type
540503
541504Sometimes in Delphi you will have a null pointer variable representing an object. While it might seem a complex situation, it is oddly quite common especially in large component packs as a method of preventing too many circular includes between objects in different units. In Delphi it is then possible to send this null pointer to a function expecting that object, without bothering to typecast to actual type, in fpc you must typecast.
542505
543506For example -
544507
545-<table>
546-<thead>
547-<tr>
548-<th><p>Delphi</p></th>
549-<th><p>OBJFPC</p></th>
550-</tr>
551-</thead>
552-<tbody>
553-<tr>
554-<td><div class="sourceCode" id="cb1"><pre class="sourceCode pascal"><code class="sourceCode pascal"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a><span class="kw">Unit</span> <span class="dv">1</span></span>
555-<span id="cb1-2"><a href="#cb1-2" aria-hidden="true" tabindex="-1"></a> <span class="kw">Type</span> </span>
556-<span id="cb1-3"><a href="#cb1-3" aria-hidden="true" tabindex="-1"></a> TSomeObject=<span class="kw">class</span>(TComponent)</span>
557-<span id="cb1-4"><a href="#cb1-4" aria-hidden="true" tabindex="-1"></a> <span class="co">//More code...</span></span>
558-<span id="cb1-5"><a href="#cb1-5" aria-hidden="true" tabindex="-1"></a> <span class="kw">End</span>;</span>
559-<span id="cb1-6"><a href="#cb1-6" aria-hidden="true" tabindex="-1"></a></span>
560-<span id="cb1-7"><a href="#cb1-7" aria-hidden="true" tabindex="-1"></a> <span class="kw">Procedure</span> DoSomething(Value: TSomeObject);</span>
561-<span id="cb1-8"><a href="#cb1-8" aria-hidden="true" tabindex="-1"></a> <span class="kw">Function</span> GetSomeObject: TSomeObject;</span>
562-<span id="cb1-9"><a href="#cb1-9" aria-hidden="true" tabindex="-1"></a></span>
563-<span id="cb1-10"><a href="#cb1-10" aria-hidden="true" tabindex="-1"></a><span class="kw">Unit</span> <span class="dv">2</span></span>
564-<span id="cb1-11"><a href="#cb1-11" aria-hidden="true" tabindex="-1"></a> <span class="kw">Type</span> </span>
565-<span id="cb1-12"><a href="#cb1-12" aria-hidden="true" tabindex="-1"></a> TSomeComponent=<span class="kw">class</span>(TComponent)</span>
566-<span id="cb1-13"><a href="#cb1-13" aria-hidden="true" tabindex="-1"></a> <span class="co">//More code...</span></span>
567-<span id="cb1-14"><a href="#cb1-14" aria-hidden="true" tabindex="-1"></a> <span class="kw">Published</span> SomeObject: <span class="dt">Pointer</span>;</span>
568-<span id="cb1-15"><a href="#cb1-15" aria-hidden="true" tabindex="-1"></a> <span class="co">//More code...</span></span>
569-<span id="cb1-16"><a href="#cb1-16" aria-hidden="true" tabindex="-1"></a> <span class="kw">End</span>;</span>
570-<span id="cb1-17"><a href="#cb1-17" aria-hidden="true" tabindex="-1"></a></span>
571-<span id="cb1-18"><a href="#cb1-18" aria-hidden="true" tabindex="-1"></a>Application</span>
572-<span id="cb1-19"><a href="#cb1-19" aria-hidden="true" tabindex="-1"></a><span class="kw">var</span> </span>
573-<span id="cb1-20"><a href="#cb1-20" aria-hidden="true" tabindex="-1"></a> MyComponent: TSomeComponent;</span>
574-<span id="cb1-21"><a href="#cb1-21" aria-hidden="true" tabindex="-1"></a><span class="kw">begin</span></span>
575-<span id="cb1-22"><a href="#cb1-22" aria-hidden="true" tabindex="-1"></a> MyComponent.SomeObject:=GetSomeObject;</span>
576-<span id="cb1-23"><a href="#cb1-23" aria-hidden="true" tabindex="-1"></a> <span class="co">//More code...</span></span>
577-<span id="cb1-24"><a href="#cb1-24" aria-hidden="true" tabindex="-1"></a> DoSomething(MyComponent.SomeObject);</span>
578-<span id="cb1-25"><a href="#cb1-25" aria-hidden="true" tabindex="-1"></a><span class="kw">end</span>;</span></code></pre></div></td>
579-<td><div class="sourceCode" id="cb2"><pre class="sourceCode pascal"><code class="sourceCode pascal"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true" tabindex="-1"></a><span class="kw">Unit</span> <span class="dv">1</span></span>
580-<span id="cb2-2"><a href="#cb2-2" aria-hidden="true" tabindex="-1"></a> <span class="kw">Type</span> </span>
581-<span id="cb2-3"><a href="#cb2-3" aria-hidden="true" tabindex="-1"></a> TSomeObject=<span class="kw">class</span>(TComponent)</span>
582-<span id="cb2-4"><a href="#cb2-4" aria-hidden="true" tabindex="-1"></a> <span class="co">//More code...</span></span>
583-<span id="cb2-5"><a href="#cb2-5" aria-hidden="true" tabindex="-1"></a> <span class="kw">End</span>;</span>
584-<span id="cb2-6"><a href="#cb2-6" aria-hidden="true" tabindex="-1"></a></span>
585-<span id="cb2-7"><a href="#cb2-7" aria-hidden="true" tabindex="-1"></a> <span class="kw">Procedure</span> DoSomething(Value: TSomeObject);</span>
586-<span id="cb2-8"><a href="#cb2-8" aria-hidden="true" tabindex="-1"></a> <span class="kw">Function</span> GetSomeObject: TSomeObject;</span>
587-<span id="cb2-9"><a href="#cb2-9" aria-hidden="true" tabindex="-1"></a></span>
588-<span id="cb2-10"><a href="#cb2-10" aria-hidden="true" tabindex="-1"></a><span class="kw">Unit</span> <span class="dv">2</span></span>
589-<span id="cb2-11"><a href="#cb2-11" aria-hidden="true" tabindex="-1"></a> <span class="kw">Type</span> TSomeComponent=<span class="kw">class</span>(TComponent)</span>
590-<span id="cb2-12"><a href="#cb2-12" aria-hidden="true" tabindex="-1"></a> <span class="co">//More code...</span></span>
591-<span id="cb2-13"><a href="#cb2-13" aria-hidden="true" tabindex="-1"></a> <span class="kw">Published</span> SomeObject: <span class="dt">Pointer</span>;</span>
592-<span id="cb2-14"><a href="#cb2-14" aria-hidden="true" tabindex="-1"></a> <span class="co">//More code...</span></span>
593-<span id="cb2-15"><a href="#cb2-15" aria-hidden="true" tabindex="-1"></a> <span class="kw">End</span>;</span>
594-<span id="cb2-16"><a href="#cb2-16" aria-hidden="true" tabindex="-1"></a></span>
595-<span id="cb2-17"><a href="#cb2-17" aria-hidden="true" tabindex="-1"></a>Application</span>
596-<span id="cb2-18"><a href="#cb2-18" aria-hidden="true" tabindex="-1"></a><span class="kw">var</span> </span>
597-<span id="cb2-19"><a href="#cb2-19" aria-hidden="true" tabindex="-1"></a> MyComponent: TSomeComponent;</span>
598-<span id="cb2-20"><a href="#cb2-20" aria-hidden="true" tabindex="-1"></a><span class="kw">begin</span></span>
599-<span id="cb2-21"><a href="#cb2-21" aria-hidden="true" tabindex="-1"></a> MyComponent.SomeObject:=<span class="dt">Pointer</span>(GetSomeObject);</span>
600-<span id="cb2-22"><a href="#cb2-22" aria-hidden="true" tabindex="-1"></a> <span class="co">//More code...</span></span>
601-<span id="cb2-23"><a href="#cb2-23" aria-hidden="true" tabindex="-1"></a> DoSomething(TSomeObject(MyComponent.SomeObject));</span>
602-<span id="cb2-24"><a href="#cb2-24" aria-hidden="true" tabindex="-1"></a><span class="kw">end</span>;</span></code></pre></div></td>
603-</tr>
604-</tbody>
605-</table>
508+**Delphi**
606509
510+**OBJFPC**
511+
512+``` pascal
513+Unit 1
514+ Type
515+ TSomeObject=class(TComponent)
516+ //More code...
517+ End;
518+
519+ Procedure DoSomething(Value: TSomeObject);
520+ Function GetSomeObject: TSomeObject;
521+
522+Unit 2
523+ Type
524+ TSomeComponent=class(TComponent)
525+ //More code...
526+ Published SomeObject: Pointer;
527+ //More code...
528+ End;
529+
530+Application
531+var
532+ MyComponent: TSomeComponent;
533+begin
534+ MyComponent.SomeObject:=GetSomeObject;
535+ //More code...
536+ DoSomething(MyComponent.SomeObject);
537+end;
538+```
539+
540+``` pascal
541+Unit 1
542+ Type
543+ TSomeObject=class(TComponent)
544+ //More code...
545+ End;
546+
547+ Procedure DoSomething(Value: TSomeObject);
548+ Function GetSomeObject: TSomeObject;
549+
550+Unit 2
551+ Type TSomeComponent=class(TComponent)
552+ //More code...
553+ Published SomeObject: Pointer;
554+ //More code...
555+ End;
556+
557+Application
558+var
559+ MyComponent: TSomeComponent;
560+begin
561+ MyComponent.SomeObject:=Pointer(GetSomeObject);
562+ //More code...
563+ DoSomething(TSomeObject(MyComponent.SomeObject));
564+end;
565+```
566+
607567#### Resources
608568
609569> **Note:** The section below may not be necessary. Any recent version of Lazarus directly supports .res files. The Windows Lazarus installer includes a resource compiler which supports .rc files. On *nix, please make sure windres is installed so you can use .rc files. See <http://wiki.lazarus.freepascal.org/Lazarus_Resources#FPC_resources>
610570
611571Delphi resource files are win32 specific and not compatible with Lazarus, so you'll have to recreate and compile them using the lazres tool. Lazres can be found in the lazarus/tools subdirectory. If you've downloaded the Lazarus sources, you'll need to compile it first.
612572
613573- cd lazarus/tools
614574- make install
615575
616576To add a resource to your application:
617577
618578- lazres myresource.lrs mypix.xpm anotherpix.xpm
619579- Add the LResources unit to your Uses clause
620580- Include the .lrs file you created under the initialization block
621581
622582Example:
623583
624584``` pascal
625585function TForm1.LoadGlyph(const GlyphName: String): TBitMap;
626586begin
627587 Result:= TPixmap.Create;
628588 Result.LoadFromLazarusResource(GlyphName);
629589end;
630590//More code...
631591begin
632592 Speedbutton1.glyph:= LoadGlyph('mypix');
633593 //More code...
634594end;
635595
636596initialization
637597{$I unit1.lrs}
638598{$I myresource.lrs}
639599end.
640600```
641601
642602### Another method to convert a Delphi or Kylix project to Lazarus
643603
644604- Rename or copy all .dfm or .xfm files to .lfm (Very old Delphi versions do not produce a text-based .dfm file. The convert utility, if present in the \bin folder can be used to covert the .dfm first))
645605- Rename or copy .dpr file to .lpr
646606- Make all necessary changes to .lpr file:
647607
6486081. Add {\$mode delphi}{\$H+} or {\$mode objfpc}{H+} directives
6496092. Add 'Interfaces' to uses clause
6506103. Comment out or delete {\$R *.res} or directive if needed
651611
652612- Make necessary changes to all .pas unit files:
653613
6546141. Add {\$mode delphi}{\$H+} or {\$mode objfpc}{H+} directives
6556152. Add 'LResources' - to do: check if this is still needed for any vaguely new Lazarus version
6566163. If the form has buttons, add 'Buttons' to uses clause
6576174. Comment out or delete {\$R *.dfm} or {\$R *.xfm} directive
6586185. Add 'Initialization' section at the end of each unit file, and add {\$I unitname.lrs} directive in it
659619
660620- Select Project-\>New Project from file
661621- Select the .lpr file
662622- In the 'Create a new project' window, choose 'Application'
663623- Build project and make further necessary corrections to get proper compilation. At this point the .lpi file is generated automaticaly. You may get 'Error reading Form' messages, click on 'Continue Loading' if you do.
664624- Save all, and you have a Lazarus project :-)
665625
666626## Getting Help
667627
668628If you encounter a problem during conversion that you just can't solve, there are a wide variety of places to get help.
669629
670-<table>
671-<tbody>
672-<tr>
673-<td colspan="2"><h3 id="documentation">Documentation</h3></td>
674-</tr>
675-<tr>
676-<td><p>For pure Object Pascal and FPC issues</p></td>
677-<td style="vertical-align: top"><p>The best place to start is the Free Pascal <a href="http://www.freepascal.org/docs-html/">Documentation</a> by Michaël Van Canneyt and Florian Klämpfl.</p></td>
678-</tr>
679-<tr>
680-<td><p>For more Lazarus oriented problems</p></td>
681-<td style="vertical-align: top"><p>The Lazarus Project Documentation in the Lazarus-CCR Knowledgebase [[Main Page]] is the next place to look.</p></td>
682-</tr>
683-<tr>
684-<td colspan="2"><h3 id="peer_support">Peer support</h3></td>
685-</tr>
686-<tr>
687-<td style="white-space: nowrap"><p>Mailing lists</p></td>
688-<td style="vertical-align: top"><p>You can post a question on any of the <a href="http://www.freepascal.org/maillist.html">mailing lists for the Free Pascal Compiler</a> or the <a href="http://forum.lazarus.freepascal.org/index.php?action=forum">FPC/Lazarus forums</a> where a lot of experts are subscribed.</p></td>
689-</tr>
690-<tr>
691-<td style="white-space: nowrap"><p>If you have access to IRC:</p></td>
692-<td style="vertical-align: top"><p>On irc.freenode.net: <a href="irc://irc.freenode.net/fpc">#fpc</a> for FPC, or <a href="irc://irc.freenode.net/lazarus-ide">#lazarus-ide</a> for Lazarus</p></td>
693-</tr>
694-</tbody>
695-</table>
630+### Documentation
631+
632+For pure Object Pascal and FPC issues
633+
634+The best place to start is the Free Pascal [Documentation](http://www.freepascal.org/docs-html/) by Michaël Van Canneyt and Florian Klämpfl.
635+
636+For more Lazarus oriented problems
637+
638+The Lazarus Project Documentation in the Lazarus-CCR Knowledgebase [[Main Page]] is the next place to look.
639+
640+### Peer support
641+
642+Mailing lists
643+
644+You can post a question on any of the [mailing lists for the Free Pascal Compiler](http://www.freepascal.org/maillist.html) or the [FPC/Lazarus forums](http://forum.lazarus.freepascal.org/index.php?action=forum) where a lot of experts are subscribed.
645+
646+If you have access to IRC:
647+
648+On irc.freenode.net: [\#fpc](irc://irc.freenode.net/fpc) for FPC, or [\#lazarus-ide](irc://irc.freenode.net/lazarus-ide) for Lazarus
696649
697650### Knowledge bases
698651
699652There are some outstanding search and knowledge bases online that can also be a great help for learning new techniques and solving problems:
700653
701654- Tamarack Associates operates a fast \[ <http://codenewsfast.com/> search\] engine specifically for the Borland usenet archives.
702655- Mer Systems Inc. provides a similar search [engine](http://www.mers.com/searchsite.html).
703656- Another outstanding source of information along with a sitewide [search](http://www.efg2.com/Lab/search.htm) capability is Earl F. Glynn's Computer Lab and Reference [Library](http://www.efg2.com/).
704657
705658## Packaging and Releasing your component
706659
707660### Creating a Lazarus package for your component(s)
708661
709662Creating a package makes installing the code you've converted a much easier process... especially if you're providing more than one component. Mattias Gärtner has written an overview of [[Lazarus Packages]] that should be read before beginning this process.
710663
711664### Documentation
712665
713666The purpose of this site and the wiki format is to make the generation of professional documentation an easy and quick process. The wiki also makes it possible to see the results of your posting immediately and make any changes you'd like in real time.
714667
715668Using the Lazarus-CCR wiki to create nice looking documentation is very easy. If you've never used wiki markup before, you can get familiar with it in the [[Sand Box]] practice area.
716669
717670### Creating a Code Release Page
718671
719672The Code Release Page contains vital information about your component that a potential downloader will need to know, such as license, intended platform, status (alpha, beta, stable...), where to download it, who wrote it, is support available... etc.
720673
721674The following procedure will let you create a Code Release Page with your browser:
722675
723676- Go to the [[Release new component]]
724677- Type the name of your component in the textbox and click on *Create Article*
725678- Fill in the template and hit save.
726679- Edit the [[Components and Code examples]] page and add the link to your newly created page to the "Released Components" section. Save the modified page.
727680
728681### Submitting the component
729682
730683If you're a release technician on the project, upload your component to the SourceForge File Release System and add it to the list of release packages. Otherwise send it to one of the project administrators (Tom Lisjac or Vincent Snijders) and we'll add it to the repository. Before we upload it to SourceForge, you have to create a *Code Release Page* to describe your component. You can use the [[Release new component]] page, to start creating such a page.
731684
732685If you think you need to continue to develop on the component, we can also put it into SVN so you'll continue to have access to it. If we get tired from committing your patches, we will give you write access to the SVN, so you can commit your patches yourself. For details see [[Using the Lazarus-ccr SVN repository]].
733686
734687## See also
735688
736689- [[Lazarus For Delphi Users]]
737690- [[Delphi language features missing from the Free Pascal Compiler]]
738691
739692---
740693*From the Free Pascal wiki, page "Code Conversion Guide", as it stood on 2023-11-06 after a change by Bart, 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