Sign in Join
Wiki copytemporary

IDE tricks: what changed

Revision 5 to 6. Removed lines have a minus sign; added lines have a plus sign.

OldNewLine
11## Create a new file with Open file
22
3-You can create a new file and save it, or you can create a new file with filename and file type in one step: Just open file (`Ctrl+o`) and select a nonexistent filename. For example: unit1.pas. The IDE will ask you if it should be created.
3+You can create a new file and save it, or you can create a new file with filename and file type in one step: Just open file (`Ctrl+o`) and select a nonexistent filename. For example: unit1.pas. The IDE will ask you if it should be created.
44
55## Customize new unit / form
66
7-Since 0.9.27 you can right click on the 'New unit' (New form) speedbutton and set the file type that should be created. You can register more file types via the IDEIntf or the project templates package.
7+Since 0.9.27 you can right click on the 'New unit' (New form) speedbutton and set the file type that should be created. You can register more file types via the IDEIntf or the project templates package.
88
99## IDE macros
1010
1111[[IDE Macros in paths and filenames]]
1212
1313## IDE directives
1414
1515[[IDE directives]]
1616
1717## Getting the compiler command line parameters created by the IDE
1818
19-You can copy the parameters from Project -\> Compiler Options -\> Show Options. Here the paths are relative to the project directory. So in most cases you can copy them without adjusting.
19+You can copy the parameters from Project -> Compiler Options -> Show Options. In most cases you can copy them without adjusting.
2020
21-The parameters are also saved to the *.compiled file. For example if your project is called test1.lpi, then a test1.compiled is created. It is a simple text XML file, so you can just copy the options and adjust the paths to compile on another computer. The file is put into the same directory, where the executable is created.
21+The parameters are also saved to the *.compiled file. For example if your project is called test1.lpi, then a test1.compiled is created. It is a simple text XML file, so you can just copy the options and adjust the paths to compile on another computer. The file is put into the same directory, where the executable is created.
2222
23-For packages this works the same.
23+For packages this works the same.
2424
25-This way, you can compile your (hopefully working and bug free) code, outside of the Lazarus IDE.
25+This way, you can compile your (hopefully working and bug free) code, outside of the Lazarus IDE.
2626
2727## Closing all editor files except one
2828
29-Under GTK (available for Linux, macOS and FreeBSD) the source editor pages have a close button to the right of their page name. Press the `Ctrl` key while clicking on the button, closes all files except the clicked one.
29+Under GTK (available for Linux, macOS and FreeBSD) the source editor pages have a close button to the right of their page name. Press the `Ctrl` key while clicking on the button, closes all files except the clicked one.
3030
3131## Component palette
3232
3333### Finding a component in the palette
3434
35-You know the component name, or part of it, but you don't know on which page it was? This tool finds it: Right click on any component in the palette to open the popup menu. Select 'View all' from the menu; this will pop open a dialog(also you can achieve it by pressing `Ctrl+Alt+P`). Enter the (partial) component name in the 'Find' box to filter the list.
35+To quickly find a component by its name, you can use the "**Component List** " window located in the "**View** " menu or simply press `Ctrl+Alt+P`. You can also call it by right-clicking on any component in the palette and selecting "**View All** " in the context menu.
3636
37+This window has a filter that allows you to find any component by part of its name and add it to the form by pressing `↵ Enter`.
38+
3739### Open the package of a component in the palette
3840
39-Right click on the component to open the popup menu, then choose open package.
41+Right click on the component to open the popup menu, then choose open package.
4042
4143### Find the source declaration of a component in the palette
4244
43-Right click on the component to open the popup menu, then choose open unit.
45+Right click on the component to open the popup menu, then choose open unit.
4446
4547### My application freezes my Linux desktop while debugging
4648
47-X (your desktop) can freeze, when an application that grabbed the mouse is stopped by gdb (the debugger).
49+X (your desktop) can freeze, when an application that grabbed the mouse is stopped by gdb (the debugger).
4850
4951### Using a second X session
5052
51-You can start a second X by:
52-
53-```text
54- X :1 &
53+You can start a second X by:
5554```
56-
57-with `Ctrl-Alt-F7` you switch to :0 and with `Ctrl-Alt-F8` you switch to :1 after that you can start a second gnome session by:
55+X :1 &
56+```
5857
59-```text
60- gnome-session --display=:1 &
58+with `Ctrl-Alt-F7` you switch to :0 and with `Ctrl-Alt-F8` you switch to :1 after that you can start a second gnome session by:
6159```
60+gnome-session --display=:1 &
61+```
6262
6363### Using VNC
6464
65-You can use vncserver/client by installing tightvncserver or realvncserver. Start the server with:
66-
67-```text
68- vncserver :1
65+You can use vncserver/client by installing tightvncserver or realvncserver. Start the server with:
6966```
67+vncserver :1
68+```
7069
71-AFAIK, a session is also started. You can connect to the vncserver with vncviewer.
70+AFAIK, a session is also started. You can connect to the vncserver with vncviewer.
7271
7372### Debug the application on the second server
7473
75-In Lazarus, in the run parameters for your project, check "use display" and enter
76-
77-```text
78- :1
74+In Lazarus, in the run parameters for your project, check "use display" and enter
7975```
76+:1
77+```
8078
81-Now your application will run on the second server, so when it is being debugged, only the second server will freeze (but that won't affect you since you are debugging on the first).
79+Now your application will run on the second server, so when it is being debugged, only the second server will freeze (but that won't affect you since you are debugging on the first).
8280
8381## Compiling the IDE fast
8482
85-Working on Lazarus itself means rebuilding the IDE many times. If you use the following tricks and have enough memory and a recent CPU, you should be able to recompile the IDE in a few seconds.
83+Working on Lazarus involves recompiling the IDE many times. The following tips can help speed up the process:
8684
87-- Put the Lazarus sources on a fast hard disk or solid state drive. Not on a slow network filesystem.
88-- Install only needed packages.
89-- Set USESVN2REVISIONINC=0 to skip the update of the revision.inc file.
85+ * Place the Lazarus sources on a fast hard drive or solid state drive. A RAM disk is ideal, but this requires RAM and the need to constantly save changes to disk.
86+ * Only install packages that are necessary for the current development.
87+ * It is very important to open the dialog in menu **Tools > Configure "Build Lazarus"** and select the "**Automatically** " option in the "**Clean up** " group so that only the changed files are recompiled during rebuilding. The "**Clean all** " option is usually used occasionally when some build errors occur.
88+ * You can also uncheck the "**Update revision.inc** " checkbox in this window.
9089
9190## DebugLn of the IDE or a LCL application
9291
93-The IDE writes many useful hints via [[DebugLn]]. You can get these this way:
92+The IDE writes many useful hints via [[DebugLn]]. You can get these this way:
9493
95-- Windows: start Lazarus with the command line parameter *--debug-log=filename.txt*.
96-- Linux/FreeBSD/macOS/Solaris: just start Lazarus in a terminal.
94+ * Windows: start Lazarus with the command line parameter _\--debug-log=filename.txt_.
95+ * Linux/FreeBSD/macOS/Solaris: just start Lazarus in a terminal.
9796
98-This is a general LCL feature.
97+This is a general LCL feature.
9998
10099## Finding the source file of an IDE window
101100
102-- Open the IDE window.
103-- Press `Ctrl+Shift+F1` to open the help editor.
104-- Remember the window classname. Close the window.
105-- Use [[IDE Window: Find in files|Find In Files]] to find the source file of the class.
101+ * Open the IDE window.
102+ * Press `Ctrl+Shift+F1` to open the help editor.
103+ * Remember the window classname. Close the window.
104+ * Use [[IDE Window: Find in files|Find In Files]] to find the source file of the class.
106105
107106## Opening a Terminal Windows from the IDE
108107
109-Its often handy to be able to open a terminal in your current project's working directory. Maybe to use a revision control system like git or svn or for a host of other possible reasons. Here is how to add a menu item to Lazarus's Tool's menu. Thanks to taazz and other contributors to the [forum thread](https://forum.lazarus.freepascal.org/index.php/topic,42151.msg294206.html#msg294206).
108+Its often handy to be able to open a terminal in your current project's working directory. Maybe to use a revision control system like git or svn or for a host of other possible reasons. Here is how to add a menu item to Lazarus's Tool's menu. Thanks to taazz and other contributors to the [forum thread](<https://forum.lazarus.freepascal.org/index.php/topic,42151.msg294206.html#msg294206>).
110109
111-- Click Tools, Configure External Tools
112-- Click 'Add' to add a new menu item (under Tools).
113-- Set Title to (eg) "Open a Terminal"
114-- Set Program File Name to the command on your system that opens a terminal, some suggestions below.
115-- Set Parameters to what ever your terminal expects on the command line to open a specific directory and the Lazarus var that points there, \$projPath().
110+ * Click Tools, Configure External Tools
111+ * Click 'Add' to add a new menu item (under Tools).
112+ * Set Title to (eg) "Open a Terminal"
113+ * Set Program File Name to the command on your system that opens a terminal, some suggestions below.
114+ * Set Parameters to what ever your terminal expects on the command line to open a specific directory and the Lazarus var that points there, $projPath().
116115
117-Those last two vary quite a lot between systems, if you don't know the first, try looking at a list of running programs, the word 'terminal' is likely to feature. For the second, once you know the terminal's name, look up its man page or google.
116+Those last two vary quite a lot between systems, if you don't know the first, try looking at a list of running programs, the word 'terminal' is likely to feature. For the second, once you know the terminal's name, look up its man page or google.
118117
119-Some examples include -
118+Some examples include -
120119
121120| O.S. | Program File Name | Parameters |
122-|----|----|----|
123-| Ubuntu Mate | mate-terminal\|\|--tab --working-directory=\$projPath() | |
124-| xfce | exo-open\|\|--launch TerminalEmulator --working-directory \$ProjPath() | |
125-| KDE | konsole\|\|--working-dir \$projPath() | |
126-| GNOME | gnome-terminal\|\|--working-directory \$projPath() | |
127-| Mac (see below) | /User/\$HOME/bin/ttab | cd \$projPath() |
128-| Windows | cmd.exe | /k cd "\$ProjPath()" |
121+|---|---|---|
122+| Ubuntu Mate | mate-terminal | \--tab --working-directory=$projPath() |
123+| xfce | exo-open | \--launch TerminalEmulator --working-directory $ProjPath() |
124+| KDE | konsole | \--working-dir $projPath() |
125+| GNOME | gnome-terminal | \--working-directory $projPath() |
126+| Mac (see below) | /User/$HOME/bin/ttab | cd $projPath() |
127+| Windows | cmd.exe | /k cd "$ProjPath()" |
129128
130-![IDE Ext Tool](/wiki-images/3/30/ExtTool.PNG) **On the Mac**, where everything is so much easier, all you have to do is:
129+[![IDE Ext Tool](/wiki-images/3/30/ExtTool.PNG)](</File:ExtTool.PNG> "IDE Ext Tool")
131130
132-1. Install <https://www.npmjs.com/package/ttab>, its only 665 lines, use the path you installed it to instead of the example shown in the table above.
133-2. Run it so you can tick its security to access the Accessibility feature.
134-3. Then set the Lazarus Tools settings as described.
135-4. Then, from within Lazarus, Tools-\>Open Terminal, then similar to 3) tick to allow Lazarus to access the Accessibility thingo.
131+**On the Mac** , where everything is so much easier, all you have to do is:
136132
137-**On Windows**, its also necessary to tick the "Show Console" as shown in the image on the right:
133+ 1. Install <https://www.npmjs.com/package/ttab>, its only 665 lines, use the path you installed it to instead of the example shown in the table above.
134+ 2. Run it so you can tick its security to access the Accessibility feature.
135+ 3. Then set the Lazarus Tools settings as described.
136+ 4. Then, from within Lazarus, Tools->Open Terminal, then similar to 3) tick to allow Lazarus to access the Accessibility thingo.
138137
138+
139+**On Windows** , its also necessary to tick the "Show Console" as shown in the image on the right:
140+
141+
142+
139143## Object Inspector: Events: Frames: Jump to the source of an inherited event
140144
141-The [[IDE Window: Object Inspector|Object Inspector]] shows the events of inherited events as *ClassName.MethodName*. Double clicking will create a new event. `Ctrl+Mouse click` on the combobox will jump directly to the inherited method body, without creating a new method.
145+The [[IDE Window: Object Inspector|Object Inspector]] shows the events of inherited events as _ClassName.MethodName_. Double clicking will create a new event. `Ctrl+Mouse click` on the combobox will jump directly to the inherited method body, without creating a new method.
142146
143147## Events (Method properties) in the Object Inspector
144148
145-Events (Method properties) are special properties, because they need as value a code address pointer, which does not exist at design time. That's why Lazarus uses the same trick as the Delphi IDE: Every method value can be type cast to **TMethod**, which contains *Data* (the object or class pointer) and the *Code* (the address pointer). At runtime both are set. But at design time the IDE sets Data to a special key value for its internal lookup table and sets Code to nil. This means:
146-
147-- At runtime when the program loads the .lfm file the real method (Data+Code) is used
148-- At design time a method value can either be a real method (Data\<\>nil and Code\<\>nil) or a fake method (Data\<\>nil,Code=nil)
149-- The compiler has for Delphi compatibility some specials about comparing method values.
150-- The = and the \<\> operator only checks the Code, not the Data.
149+Events (Method properties) are special properties, because they need as value a code address pointer, which does not exist at design time. That's why Lazarus uses the same trick as the Delphi IDE: Every method value can be type cast to **TMethod** , which contains _Data_ (the object or class pointer) and the _Code_ (the address pointer). At runtime both are set. But at design time the IDE sets Data to a special key value for its internal lookup table and sets Code to nil. This means:
151150
152-Do not use:
151+ * At runtime when the program loads the .lfm file the real method (Data+Code) is used
152+ * At design time a method value can either be a real method (Data<>nil and Code<>nil) or a fake method (Data<>nil,Code=nil)
153+ * The compiler has for Delphi compatibility some specials about comparing method values.
154+ * The = and the <> operator only checks the Code, not the Data.
153155
154-``` pascal
155-if OnMyEvent = NewValue then exit; // wrong, because it compares only Code
156+Do **not** use:
156157```
157-
158-Because this only compares the Code. Use instead
158+if OnMyEvent = NewValue then exit; // WRONG, because it compares only Code
159+```
159160
160-``` pascal
161-if CompareMem(@FOnMyEvent, @NewValue, SizeOf(TMethod)) then exit; // correct, checking both Data and Code
161+Because this only compares the Code. Use instead:
162162```
163+if CompareMem(@FOnMyEvent, @NewValue, SizeOf(TMethod)) then exit;
164+```
163165
164-Here is an example where the = operator fails:
166+or better yet, a special function of the `LazMethodList` unit:
167+```
168+if SameMethod(TMethod(FOnMyEvent), TMethod(NewValue)) then exit;
169+```
165170
166-``` pascal
171+Here is an example where the = operator fails:
172+```
167173type
168- TMyClass = class
169- private
170- FOnClick: TNotifyEvent;
171- procedure SetOnClick(Value: TNotifyEvent);
172- public
173- procedure Click(Sender: TObject);
174- property OnClick: TNotifyEvent read FOnClick write SetOnClick;
175- end;
176-
177-procedure TMyClass.SetOnClick(Value: TNotifyEvent);
178-begin
179- if Value = FOnClick then exit; // bug, checks only for Code, not for data
180- FOnClick := Value;
181-end;
182-
183-var
184- a, b: TMyClass;
185-begin
186- a := TMyClass.Create;
187- b := TMyClass.Create;
188- a.OnClick := @a.Click;
189- a.OnClick := @b.Click; // same code, but different data, a.OnClick still points to @a.Click;
190-end.
174+ TMyClass = class
175+ private
176+ FOnClick: TNotifyEvent;
177+ procedure SetOnClick(Value: TNotifyEvent);
178+ public
179+ procedure Click(Sender: TObject);
180+ property OnClick: TNotifyEvent read FOnClick write SetOnClick;
181+ end;
182+
183+ procedure TMyClass.SetOnClick(Value: TNotifyEvent);
184+ begin
185+ if Value = FOnClick then exit; // bug, checks only for Code, not for data
186+ FOnClick := Value;
187+ end;
188+
189+ var
190+ a, b: TMyClass;
191+ begin
192+ a := TMyClass.Create;
193+ b := TMyClass.Create;
194+ a.OnClick := @a.Click;
195+ a.OnClick := @b.Click; // same code, but different data, a.OnClick still points to @a.Click;
196+ end.
191197```
192198
193199---
194-*From the Free Pascal wiki, page "IDE tricks", as it stood on 2021-10-11 after a change by Kai Burghardt, 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).*
200+*From the Free Pascal wiki, page "IDE tricks", as the Internet Archive kept it on 2025-04-16, last changed on 2025-01-19. 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