Sign in Join
Wiki copytemporary

IDE tricks/ru: what changed

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

OldNewLine
11# Создание нового файла с помощью \[функции\] "Открыть файл"
22
33Вы можете создать новый файл и сохранить его, или вы можете создать новый файл с именем файла и типом файла за один шаг: Просто откройте файл (`ctrl`+`O`) и выберите несуществующий файл. Например: unit1.pas. IDE спросит вас, нужно ли его создавать.
44
55# Настройка нового модуля / формы
66
77Начиная с версии 0.9.27 вы можете щелкнуть правой кнопкой мыши на кнопке быстрого запуска 'New unit' (New form) и установить тип файла, который должен быть создан. Вы можете зарегистрировать больше типов файлов через IDEIntf или пакет шаблонов проектов.
88
99# Макросы IDE
1010
1111[[IDE Macros in paths and filenames/ru|Макросы IDE в путях и именах файлов]]
1212
1313# Директивы IDE
1414
1515[[IDE directives]]
1616
1717# Получение параметров командной строки компилятора, созданных в среде IDE
1818
1919Вы можете скопировать параметры из Project -\> Compiler Options -\> Show Options. Здесь пути относятся к каталогу проекта. Таким образом, в большинстве случаев вы можете скопировать их без настройки.
2020
2121Параметры также сохраняются в файле *.compiled. Например, если ваш проект называется test1.lpi, то создается test1.compiled. Это простой текстовый XML-файл, поэтому вы можете просто скопировать параметры и настроить пути для компиляции на другом компьютере. Файл помещается в тот же каталог, где создается исполняемый файл.
2222
2323Это работает так же и для пакетов.
2424
2525Таким образом, вы можете скомпилировать свой (надеюсь, работающий и свободный от ошибок) код за пределами IDE lazarus.
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 right to 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
53-`  X :1 &`
53+```text
54+ X :1 &
55+```
5456
5557with 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:
5658
57-`  gnome-session --display=:1 &`
59+```text
60+ gnome-session --display=:1 &
61+```
5862
5963## Using VNC
6064
6165You can use vncserver/client by installing tightvncserver/realvncserver Start the server with:
6266
63-`  vncserver :1`
67+```text
68+ vncserver :1
69+```
6470
6571AFAIK, a session is also started. You can connect to the vncserver with vncviewer.
6672
6773## Debug the application on the second server
6874
6975In Lazarus, in the run parameters for your project, check "use display" and enter
7076
71-` :1`
77+```text
78+ :1
79+```
7280
7381Now 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).
7482
7583# Compiling the IDE fast
7684
7785Working 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.
7886
7987- Put the Lazarus sources on a fast harddisk. Not on a slow network filesystem.
8088- Install only needed packages.
8189- Set USESVN2REVISIONINC=0 to skip the update of the revision.inc.
8290
8391# DebugLn of the IDE or a LCL application
8492
8593The IDE writes many useful hints via debugln. You can get these this way:
8694
8795- Windows: start Lazarus with the command line parameter *--debug-log=filename.txt*.
8896- Linux/BSD/macOS/Solaris: just start Lazarus in a terminal.
8997
9098This is a general LCL feature.
9199
92100# Finding the source file of an IDE window
93101
94102- Open the IDE window.
95103- Press Ctrl+Shift+F1 to open the help editor.
96104- Remember the window classname. Close the window.
97105- Use [[IDE Window: Find in files|Find In Files]] to find the source file of the class.
98106
99107# Opening a Terminal Windows from the IDE
100108
101109Its 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 <https://forum.lazarus.freepascal.org/index.php/topic,42151.msg294206.html#msg294206>
102110
103111- Click Tools, Configure External Tools
104112- Click 'Add' to add a new menu item (under Tools).
105113- Set Title to (eg) "Open a Terminal"
106114- Set Program File Name to the command on your system that opens a terminal, some suggestions below.
107115- 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().
108116
109117Those 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.
110118
111119Some examples include -
112120
113121| O.S. | Program File Name | Parameters |
114122|----|----|----|
115123| Ubuntu Mate | mate-terminal\|\|--tab --working-directory=\$projPath() | |
116124| xfce | exo-open\|\|--launch TerminalEmulator --working-directory \$ProjPath() | |
117125| KDE | konsole\|\|--working-dir \$projPath() | |
118126| Mac (see below) | /User/\$HOME/bin/ttab | cd \$projPath() |
119127| Windows | ? | ? |
120128
121129On the Mac, where everything is so much easier, all you have to do is -
122130
1231311. 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.
1241322. Run it so you can tick its security to access the Accessibility feature.
1251333. Then set the Lazarus Tools settings as described.
1261344. Then, from within Lazarus, Tools-\>Open Terminal, then similar to 3) tick to allow Lazarus to access the Accessibility thingo.
127135
128136# Object Inspector: Events: Frames: Jump to the source of an inherited event
129137
130138The 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.
131139
132140# Events (Method properties) in the Object Inspector
133141
134142Events (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:
135143
136144- At runtime when the program loads the .lfm file the real method (Data+Code) is used
137145- At designtime a method value can either be a real method (Data\<\>nil and Code\<\>nil) or a fake method (Data\<\>nil,Code=nil)
138146- The compiler has for Delphi compatibility some specials about comparing method values.
139147- The = and the \<\> operator only checks the Code, not the Data.
140148
141149Do not use:
142150
143151``` pascal
144152if OnMyEvent = NewValue then exit; // wrong, because it compares only Code
145153```
146154
147155Because this only compares the Code. Use instead
148156
149157``` pascal
150158if CompareMem(@FOnMyEvent, @NewValue, SizeOf(TMethod)) then exit; // correct, checking both Data and Code
151159```
152160
153161Here is an example when the = operator fails:
154162
155163``` pascal
156164type
157165 TMyClass = class
158166 private
159167 FOnClick: TNotifyEvent;
160168 procedure SetOnClick(Value: TNotifyEvent);
161169 public
162170 procedure Click(Sender: TObject);
163171 property OnClick: TNotifyEvent read FOnClick write SetOnClick;
164172 end;
165173
166174procedure TMyClass.SetOnClick(Value: TNotifyEvent);
167175begin
168176 if Value = FOnClick then exit; // bug, checks only for Code, not for data
169177 FOnClick := Value;
170178end;
171179
172180var
173181 a, b: TMyClass;
174182begin
175183 a := TMyClass.Create;
176184 b := TMyClass.Create;
177185 a.OnClick := @a.Click;
178186 a.OnClick := @b.Click; // same code, but different data, a.OnClick still points to @a.Click;
179187end.
180188```
181189
182190---
183191*From the Free Pascal wiki, page "IDE tricks/ru", as it stood on 2019-12-22 after a change by Trev, 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