Difference between revisions of "IDE tricks"
(→Create a new file with Open file)
|Line 1:||Line 1:|
(Ctrl+o) . : unit1.pas. IDE .
= Customize new unit / form =
= Customize new unit / form =
Revision as of 10:03, 28 May 2017
- 1 Create a new file with Open file
- 2 Customize new unit / form
- 3 IDE macros
- 4 IDE directives
- 5 Getting the compiler command line parameters created by the IDE
- 6 Closing all editor files except one
- 7 Component palette
- 8 My application freezes my linux desktop while debugging
- 9 Compiling the IDE fast
- 10 DebugLn of the IDE or a LCL application
- 11 Finding the source file of an IDE window
- 12 Object Inspector: Events: Frames: Jump to the source of an inherited event
- 13 Events (Method properties) in the Object Inspector
Create a new file with Open file
You can create a new file and save it, or you can create a new file with filename and filetype in one step: Just open file (Ctrl+o) and select an non existing file. For example: unit1.pas. The IDE will ask you if it should be created.
Customize new unit / form
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.
Getting the compiler command line parameters created by the IDE
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.
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.
For packages this works the same.
This way, you can compile your (hopefully working and bugfree) code, outside of the lazarus IDE.
Closing all editor files except one
Under gtk (available for linux, mac os x and freebsd) the source editor pages have a close button right to their page name. Press the Ctrl key while clicking on the button, closes all files except the clicked one.
Finding a component in the palette
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.
Open the package of a component in the palette
Right click on the component to open the popup menu, then choose open package.
Find the source declaration of a component in the palette
Right click on the component to open the popup menu, then choose open unit.
My application freezes my linux desktop while debugging
X (your desktop) can freeze, when an application that grabbed the mouse is stopped by gdb (the debugger).
Using a second X session
You can start a second X by:
X :1 &
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:
gnome-session --display=:1 &
You can use vncserver/client by installing tightvncserver/realvncserver Start the server with:
AFAIK, a session is also started. You can connect to the vncserver with vncviewer.
Debug the application on the second server
In Lazarus, in the run parameters for your project, check "use display" and enter
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).
Compiling the IDE fast
Working on Lazarus itself needs 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.
- Put the Lazarus sources on a fast harddisk. Not on a slow network filesystem.
- Install only needed packages.
- Set USESVN2REVISIONINC=0 to skip the update of the revision.inc.
DebugLn of the IDE or a LCL application
The IDE writes many useful hints via debugln. You can get these this way:
- Windows: start Lazarus with the command line parameter --debug-log=filename.txt.
- Linux/BSD/Mac OS X/Solaris: just start Lazarus in a terminal.
This is a general LCL feature.
Finding the source file of an IDE window
- Open the IDE window.
- Press Ctrl+Shift+F1 to open the help editor.
- Remember the window classname. Close the window.
- Use Find In Files to find the source file of the class.
Object Inspector: Events: Frames: Jump to the source of an inherited event
The 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.
Events (Method properties) in the Object Inspector
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 casted to TMethod, which contains Data (the object or class pointer) and the Code (the address pointer). At runtime both are set. But at designtime the IDE sets Data to a special key value for its internal lookup table and sets Code to nil. This means:
- At runtime when the program loads the .lfm file the real method (Data+Code) is used
- At designtime a method value can either be a real method (Data<>nil and Code<>nil) or a fake method (Data<>nil,Code=nil)
- The compiler has for Delphi compatibility some specials about comparing method values.
- The = and the <> operator only checks the Code, not the Data.
Do not use:
if OnMyEvent = NewValue then exit; // wrong, because it compares only Code
Because this only compares the Code. Use instead
if CompareMem(@FOnMyEvent, @NewValue, SizeOf(TMethod)) then exit; // correct, checking both Data and Code
Here is an example when the = operator fails:
type TMyClass = class private FOnClick: TNotifyEvent; procedure SetOnClick(Value: TNotifyEvent); public procedure Click(Sender: TObject); property OnClick: TNotifyEvent read FOnClick write SetOnClick; end; procedure TMyClass.SetOnClick(Value: TNotifyEvent); begin if Value=FOnClick then exit; // bug, checks only for Code, not for data FOnClick:=Value; end; var a,b: TMyClass; begin a:=TMyClass.Create; b:=TMyClass.Create; a.OnClick:=@a.Click; a.OnClick:=@b.Click; // same code, but different data, a.OnClick still points to @a.Click; end.