Sign in Join
Wiki copytemporary

IDE tricks: what changed

Revision 3 to 4. Removed lines have a minus sign; added lines have a plus sign.

OldNewLine
11## Create a new file with Open file
22
33You 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
77Since 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
1919You 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.
2020
2121The 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
2323For packages this works the same.
2424
2525This 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
2929Under 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
3535You 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.
3636
3737### Open the package of a component in the palette
3838
3939Right click on the component to open the popup menu, then choose open package.
4040
4141### Find the source declaration of a component in the palette
4242
4343Right click on the component to open the popup menu, then choose open unit.
4444
4545### My application freezes my Linux desktop while debugging
4646
4747X (your desktop) can freeze, when an application that grabbed the mouse is stopped by gdb (the debugger).
4848
4949### Using a second X session
5050
5151You can start a second X by:
5252
5353`  X :1 &`
5454
5555with `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:
5656
5757`  gnome-session --display=:1 &`
5858
5959### Using VNC
6060
6161You can use vncserver/client by installing tightvncserver or realvncserver. Start the server with:
6262
6363`  vncserver :1`
6464
6565AFAIK, a session is also started. You can connect to the vncserver with vncviewer.
6666
6767### Debug the application on the second server
6868
6969In Lazarus, in the run parameters for your project, check "use display" and enter
7070
7171` :1`
7272
7373Now 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).
7474
7575## Compiling the IDE fast
7676
7777Working 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.
7878
7979- Put the Lazarus sources on a fast hard disk or solid state drive. Not on a slow network filesystem.
8080- Install only needed packages.
8181- Set USESVN2REVISIONINC=0 to skip the update of the revision.inc file.
8282
8383## DebugLn of the IDE or a LCL application
8484
8585The IDE writes many useful hints via [[DebugLn]]. You can get these this way:
8686
8787- Windows: start Lazarus with the command line parameter *--debug-log=filename.txt*.
8888- Linux/FreeBSD/macOS/Solaris: just start Lazarus in a terminal.
8989
9090This is a general LCL feature.
9191
9292## Finding the source file of an IDE window
9393
9494- Open the IDE window.
9595- Press `Ctrl+Shift+F1` to open the help editor.
9696- Remember the window classname. Close the window.
9797- Use [[IDE Window: Find in files|Find In Files]] to find the source file of the class.
9898
9999## Opening a Terminal Windows from the IDE
100100
101101Its 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).
102102
103103- Click Tools, Configure External Tools
104104- Click 'Add' to add a new menu item (under Tools).
105105- Set Title to (eg) "Open a Terminal"
106106- Set Program File Name to the command on your system that opens a terminal, some suggestions below.
107107- 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().
108108
109109Those 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.
110110
111111Some examples include -
112112
113113| O.S. | Program File Name | Parameters |
114114|----|----|----|
115115| Ubuntu Mate | mate-terminal\|\|--tab --working-directory=\$projPath() | |
116116| xfce | exo-open\|\|--launch TerminalEmulator --working-directory \$ProjPath() | |
117117| KDE | konsole\|\|--working-dir \$projPath() | |
118118| GNOME | gnome-terminal\|\|--working-directory \$projPath() | |
119119| Mac (see below) | /User/\$HOME/bin/ttab | cd \$projPath() |
120120| Windows | cmd.exe | /k cd "\$ProjPath()" |
121121
122-<img src="ExtTool.PNG" title="IDE Ext Tool" width="250" alt="IDE Ext Tool" /> **On the Mac**, where everything is so much easier, all you have to do is:
122+![IDE Ext Tool](/wiki-images/3/30/ExtTool.PNG) **On the Mac**, where everything is so much easier, all you have to do is:
123123
1241241. 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.
1251252. Run it so you can tick its security to access the Accessibility feature.
1261263. Then set the Lazarus Tools settings as described.
1271274. Then, from within Lazarus, Tools-\>Open Terminal, then similar to 3) tick to allow Lazarus to access the Accessibility thingo.
128128
129129**On Windows**, its also necessary to tick the "Show Console" as shown in the image on the right:
130130
131131## Object Inspector: Events: Frames: Jump to the source of an inherited event
132132
133133The [[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.
134134
135135## Events (Method properties) in the Object Inspector
136136
137137Events (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:
138138
139139- At runtime when the program loads the .lfm file the real method (Data+Code) is used
140140- 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)
141141- The compiler has for Delphi compatibility some specials about comparing method values.
142142- The = and the \<\> operator only checks the Code, not the Data.
143143
144144Do not use:
145145
146146``` pascal
147147if OnMyEvent = NewValue then exit; // wrong, because it compares only Code
148148```
149149
150150Because this only compares the Code. Use instead
151151
152152``` pascal
153153if CompareMem(@FOnMyEvent, @NewValue, SizeOf(TMethod)) then exit; // correct, checking both Data and Code
154154```
155155
156156Here is an example where the = operator fails:
157157
158158``` pascal
159159type
160160 TMyClass = class
161161 private
162162 FOnClick: TNotifyEvent;
163163 procedure SetOnClick(Value: TNotifyEvent);
164164 public
165165 procedure Click(Sender: TObject);
166166 property OnClick: TNotifyEvent read FOnClick write SetOnClick;
167167 end;
168168
169169procedure TMyClass.SetOnClick(Value: TNotifyEvent);
170170begin
171171 if Value = FOnClick then exit; // bug, checks only for Code, not for data
172172 FOnClick := Value;
173173end;
174174
175175var
176176 a, b: TMyClass;
177177begin
178178 a := TMyClass.Create;
179179 b := TMyClass.Create;
180180 a.OnClick := @a.Click;
181181 a.OnClick := @b.Click; // same code, but different data, a.OnClick still points to @a.Click;
182182end.
183183```
184184
185185---
186186*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).*

Back to history