Sign in Join
Wiki copytemporary

Lazarus IDE Tools/zh CN: what changed

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

OldNewLine
11Lazarus IDE 工具
22
33## 概述
44
55IDE使用了Pascal源码解析和编辑工具库,被称为“codetools(代码工具)”。工具提供的功能像查找声明、代码完成、提取、移动插入和美化Pascal。这些函数可以节省你很多时间,你可以在编辑器选项中对它们进行自定义配置。
66
77因为它们的工作时解析FPC、Delphi和Kylix代码。它们不需要编译单元,也不是一个安装了Borland的编译器。你可以在同一时间编辑Delphi和FPC代码。你可以使用不同版本的Delphi和FPC。这使得移植Delphi代码变得容易很多。
88
99## IDE 快捷键列表
1010
1111| | |
1212|----|----|
1313| [[Lazarus IDE Tools/zh CN|查找声明]] | `Ctrl`+点击 or `Alt`+`Up` (跳转到声明的类型或变量) |
1414| [[Lazarus IDE Tools/zh CN|方法跳转]] | `Ctrl`+`Shift`+`Up` (在定义部分和实现部分进行切换。看见一个定义,就可以用快键方式,直接找到它的实现部分。) |
1515| [[Lazarus IDE Tools/zh CN|代码模板]] | `Ctrl`+`J` |
1616| [[Lazarus IDE Tools/zh CN|Syncro 编辑(同步编辑)]] | `Ctrl`+`J` (需要选择文本) |
1717| [[Lazarus IDE Tools/zh CN|类自动完成]] | `Ctrl`+`Shift`+`C` |
1818| [[Lazarus IDE Tools/zh CN|标识符自动完成]] | `Ctrl`+`空格` |
1919| [[Lazarus IDE Tools/zh CN|关键字自动完成]] | `Ctrl`+`W` |
2020| [[Lazarus IDE Tools/zh CN|参数提示]] | `Ctrl`+`Shift`+`空格` |
2121| [[Lazarus IDE Tools/zh CN|渐进式搜索]] | `Ctrl`+`E` |
2222
2323## 方法跳转
2424
2525要在过程体(begin..end)与过程定义(procedure 过程名)间跳转,使用 `Ctrl`+`Shift`+`Up`.
2626
2727示例:
2828
29-`interface`\
29+``` pascal
30+interface
3031
31-`procedure DoSomething; // 过程定义`\
32-` `\
33-`implementation`\
34-` `\
35-`procedure DoSomething; // 过程体`\
36-`begin`\
37-`end;`
32+procedure DoSomething; // 过程定义
33+
34+implementation
35+
36+procedure DoSomething; // 过程体
37+begin
38+end;
39+```
3840
3941如果光标在过程体,当你按`Ctrl`+`Shift`+`Up`时,会跳转到其定义,再次按`Ctrl`+`Shift`+`Up`会跳转到过程体;如此循环。
4042
4143在方法间(类中的过程)也是如此。
4244
4345注意: *方法跳转*,将跳转到具有相同名称和参数列表的地方,如果没有,它将跳到最佳匹配的地方,并将光标定位在第一个上面。(对于Delphians:Delphi不能做到这一点。)
4446
4547例如,不同参数类型的过程:
4648
47-`interface`\
49+``` pascal
50+interface
4851
49-`procedure DoSomething(p: char); // 过程定义`\
52+procedure DoSomething(p: char); // 过程定义
5053
51-`implementation`\
52-`  `\
53-`procedure DoSomething(p: string); // 过程主体`\
54-`begin`\
55-`end;`
54+implementation
55+
56+procedure DoSomething(p: string); // 过程主体
57+begin
58+end;
59+```
5660
5761自定义跳转会在'string'处定位光标,这可用于重命名方法或改变参数。
5862
5963如:\
6064你更名'DoSomething' 为 'MakeIt':
6165
62-`interface`\
66+``` pascal
67+interface
6368
64-`procedure MakeIt; // 过程定义`\
69+procedure MakeIt; // 过程定义
6570
66-`implementation`\
71+implementation
6772
68-`procedure DoSomething; // 过程主体`\
69-`begin`\
70-`end;`
73+procedure DoSomething; // 过程主体
74+begin
75+end;
76+```
7177
7278Then you jump from MakeIt to the body. The IDE searches for a fitting body, does not find one, and hence searches for a candidate. Since you renamed only one procedure there is exactly one body without definition (DoSomething) and so it will jump to DoSomething and position the cursor right on 'DoSomething'. Then you can simply rename it there too. This works for parameters as well.
7379
7480## 引入文件
7581
7682引入文件是使用{\$I 文件名} 或 {\$INCLUDE 文件名}编译指令。Lazarus和FPC大量采用它,以减少冗余,为考虑平台兼容性,可以使用{\$IFDEF}结构。
7783
7884Contrary to Delphi, the Lazarus IDE has full support for include files. You can for example jump from the method in the .pas file to the method body in the include file. All codetools like code completion consider include files as special bounds.
7985
8086For instance: When code completion adds a new method body behind another method body, it keeps them both in the same file. This way you can put whole class implementations in include files, like the LCL does for nearly all controls.
8187
8288But there is a newbie trap: If you open an include file for the first time and try method jumping or find declaration you will get an error. The IDE does not know to which unit the include file belongs. You must open the unit first.
8389
8490As soon as the IDE parses the unit, it will parse the include directives there and the IDE will remember this relationship. It saves this information on exit and on project save to ~/.lazarus/includelinks.xml. The next time you open this include file and jump or do a find declaration, the IDE will internally open the unit and the jump will work. You can also hint the IDE by putting
8591
86-`{%mainunit yourunit.pas} `
92+```text
93+{%mainunit yourunit.pas}
94+```
8795
8896on the top of yourinclude.inc.
8997
9098This mechanism has of course limits. Some include files are included twice or more. For example: lcl/include/winapih.inc.
9199
92100Jumping from the procedure/method definitions in this include file to the bodies depends on your last actions. If you worked on lcl/lclintf.pp the IDE will jump to winapi.inc. If you worked on lcl/interfacebase.pp, then it will jump to lcl/include/interfacebase.inc (or one of the other include files). If you are working on both, then you can get confused. ;)
93101
94102## 代码模板
95103
96104代码模板将标识符转换为文本或代码片段。
97105
98106默认快捷键是`Ctrl`+`J`。输入一个标识符,之后按`Ctrl`+`J`键将会替换该标识符为选定的内容。代码模板可以在“工具”菜单-\>“选项“-\>“代码工具”里设置。
99107
100108如,在标识符classf后按`Ctrl`+`J`,classf将被替换为:
101109
102-`T = class(T)`\
103-`private`\
110+``` pascal
111+T = class(T)
112+private
104113
105-`public`\
106-`  constructor Create;`\
107-`  destructor Destroy; override;`\
108-`end;`
114+public
115+ constructor Create;
116+ destructor Destroy; override;
117+end;
118+```
109119
110120并且光标在T后面。你可以将光标定位在空白位置(而不是标识符那里),按下 `Ctrl`+`J`键,将显示代码模板列表。选择一个,将返回选择的代码模板。
111121
112122输入b之后,按`Ctrl`+`J`键,将显示 begin..end; 块。
113123
114124## 参数提示
115125
116126显示参数提示。
117127
118128例如:
119129
120-`Canvas.FillRect();`
130+```text
131+Canvas.FillRect();
132+```
121133
122134将光标置于括号中,按`Ctrl`+`Shift`+`space`键,将显示FillRect的参数提示信息。
123135
124136## 渐进式搜索
125137
126138渐进式搜索,按`Ctrl`+`E`,输入搜索的文本,编辑器会高亮所有搜索到的。
127139
128140- 例如,输入`e`,将搜索并高亮显示所有e的匹配项。
129141- 然后,输入`t` ,将突出显示所有匹配et的文本。
130142- 跳转到下一个匹配项,按 `F3`或(`Ctrl`+`E`);跳转到上一匹配项,按`Shift`+`F3`。
131143- `Backspace` 删除最后一个字符。
132144- 停止搜索,可以按`Enter`键,或者在代码编辑器中点击鼠标。
133145- You can resume the last search by pressing `Ctrl`+`e` a second time, immediately after you started incr-search with `Ctrl`+`e`. that is while the search term is still empty.
134146- `Ctrl`+`V`键,粘贴剪贴板中的内容到当前搜索(因为lazarus 0.9.27 r19824)。
135147
136148### 注意:快速搜索与渐进式搜索的标识符
137149
138150- Place text cursor on identifier (do not select anything) ~~将光标放在标识符处(不要选择任何内容)。~~
139151- 按`Ctrl`+`C`键,将复制选择的标识符到剪贴板。
140152- 按`Ctrl`+`E`键,开始渐进式搜索。
141153- 按`Ctrl`+`V`键,搜索标识符(自0.9.27)。
142154- `F3`,向下搜索,`Shift`+`F3`向下搜索。
143155- 使用任意键(如,光标左、右键)来终止搜索。
144156
145157## Syncro 编辑(同步编辑)
146158
147159Syncro Edit(同步编辑)可以让你在同一时间同步编辑所有匹配到的内容。你简单的在一个地方编辑,所有匹配的内容也会同步更新。
148160
149161它适用于所有选择区域的文本:
150162
151163- 选择文本块。
152164- 按`Ctrl`+`J`或,点击编辑左侧显示的“编辑图标”(![](/wiki-images/7/7e/SyncroEditIcon.png))。按`tab`键,选择要编辑的内容。
153165- 输入新内容。
154166- 按`Esc`键完成编辑。
155167
156168这里有[[New IDE features since|动画演示]]。
157169
158170> **Note:** `Ctrl`+`J`也是代码模板的快捷键,如果你选择的不是文本块的话。
159171
160172## 查找下一个/上一个出现的单词
161173
162174这两个功能,可以在源代码编辑器的弹出菜单中找到:
163175
164176- 源代码编辑器 / 弹出菜单 / 查找 / 查找下一个发现的词
165177- 源代码编辑器 / 弹出菜单 / 查找 / 查找前一个发现的词
166178
167179And you can assign them shortcuts in the editor options.~~你也可以在查找菜单中,找到相应菜单项,它与其功能相同,当然也可以使用快捷键。~~
168180
169181## 代码自动完成
170182
171183代码自动完成,可以在“编辑”菜单-\>“自动完成代码”,或按`Ctrl`+`Shift`+`C`键。(新版的Lazarus,在“Source”菜单-\>“自动完成代码”)
172184
173185对于Delphians:
174186
175187Delphi的“代码完成”,按`Ctrl`+`Space`将显示标识符列表。在Lazarus中称为“标识符提示”。
176188
177189代码自动完成,有多种强大功能:
178190
179191- 类完成:自动完成属性,在方法体中增加/更新私有变量或私有方法。
180192- [[Basic Pascal Tutorial/Chapter 4/Forward Referencing/zh CN|前向引用]]过程完成: 添加过程体。
181193- 事件赋值完成:完成事件赋值,并增加了方法定义和主体。
182194- 变量声明完成:增加了局部变量定义。
183195- 过程调用完成:添加新过程。
184196- 反转过程完成:添加过程/函数体声明。
185197- 反转类完成:添加了方法体声明。
186198
187199这个功能的使用,取决于编辑器中光标的位置,下面进行说明。
188200
189201### 类自动完成
190202
191203(翻译不完善不完整,需要修订)
192204
193205“类完成”是代码完成中最强大的,编写一个类,添加方法和属性,代码完成,将添加方法休,属性访问方法和变量。
194206
195207如,创建一个类(见代码模板,以节省你的工作时间):
196208
197-`TExample = class(TObject)`\
198-`public`\
199-`  constructor Create;`\
200-`  destructor Destroy; override;`\
201-`end;`
209+``` pascal
210+TExample = class(TObject)
211+public
212+ constructor Create;
213+ destructor Destroy; override;
214+end;
215+```
202216
203217在类中,按`Ctrl`+`Shift`+`C`键,将会创建缺少的方法,并将光标移到创建的第一个方法体中,所以,你可以开始编写类代码:
204218
205-`{ TExample }`\
219+``` pascal
220+{ TExample }
206221
207-`constructor TExample.Create;`\
208-`begin`\
209-`  |`\
210-`end;`\
222+constructor TExample.Create;
223+begin
224+ |
225+end;
211226
212-`destructor TExample.Destroy;`\
213-`begin`\
214-`  inherited Destroy;`\
215-`end;`
227+destructor TExample.Destroy;
228+begin
229+ inherited Destroy;
230+end;
231+```
216232
217233留意: '\|'是光标位置。
218234
219235提示:你可以按按`Ctrl`+`Shift`+`Up`键,在方法与方法体间跳转。
220236
221237你可以看到,在IDE中加入了继承销毁,因为,在类中定义了override关键字。
222238
223239现在,添加一个DoSomething方法:
224240
225-`TExample = class(TObject)`\
226-`public`\
227-`  constructor Create;`\
228-`  procedure DoSomething(i: integer);`\
229-`  destructor Destroy; override;`\
230-`end;`
241+``` pascal
242+TExample = class(TObject)
243+public
244+ constructor Create;
245+ procedure DoSomething(i: integer);
246+ destructor Destroy; override;
247+end;
248+```
231249
232250按`Ctrl`+`Shift`+`C`,将添加:
233251
234-`procedure TExample.DoSomething(i: integer);`\
235-`begin`\
236-`  |`\
237-`end;`
252+``` pascal
253+procedure TExample.DoSomething(i: integer);
254+begin
255+ |
256+end;
257+```
238258
239259你可以看到新的方法体中插入了创建和销毁,因为在类中已经定义。You can define the insertion policy in Environment \> Codetools Options -\> Code Creation.
240260
241261**完成属性** 添加一个AnInteger属性:
242262
243-`TExample = class(TObject)`\
244-`public`\
245-`  constructor Create;`\
246-`  procedure DoSomething(i: integer);`\
247-`  destructor Destroy; override;`\
248-`  property AnInteger: Integer;`\
249-`end;`
263+``` pascal
264+TExample = class(TObject)
265+public
266+ constructor Create;
267+ procedure DoSomething(i: integer);
268+ destructor Destroy; override;
269+ property AnInteger: Integer;
270+end;
271+```
250272
251273按`Ctrl`+`Shift`+`C`将得到:
252274
253-`procedure TExample.SetAnInteger(const AValue: integer);`\
254-`begin`\
255-`  |if FAnInteger=AValue then exit;`\
256-`  FAnInteger:=AValue;`\
257-`end;`
275+``` pascal
276+procedure TExample.SetAnInteger(const AValue: integer);
277+begin
278+ |if FAnInteger=AValue then exit;
279+ FAnInteger:=AValue;
280+end;
281+```
258282
259283代码完成增加了一个写访问修饰符,并增加了一些常代码,跳转到类,按`Ctrl`+`Shift`+`Up`:
260284
261-`TExample = class(TObject)`\
262-`private`\
263-`  FAnInteger: integer;`\
264-`  procedure SetAnInteger(const AValue: integer);`\
265-`public`\
266-`  constructor Create;`\
267-`  procedure DoSomething(i: integer);`\
268-`  destructor Destroy; override;`\
269-`  property AnInteger: integer read FAnInteger write SetAnInteger;`\
270-`end;`
285+``` pascal
286+TExample = class(TObject)
287+private
288+ FAnInteger: integer;
289+ procedure SetAnInteger(const AValue: integer);
290+public
291+ constructor Create;
292+ procedure DoSomething(i: integer);
293+ destructor Destroy; override;
294+ property AnInteger: integer read FAnInteger write SetAnInteger;
295+end;
296+```
271297
272298该属性继承了一个读取和写入访问修饰符,这个类得到了一个新的private(私有)变量FAnInteger和SetAnInteger方法。
273299
274300It is a common Delphi style rule to prepend private variables with an 'F' and the write method with a 'Set'. If you don't like that, you can change this in Environment \> Codetools Options -\> Code Creation.
275301
276302创建一个只读属性:
277303
278-`property PropName: PropType read;`
304+```text
305+property PropName: PropType read;
306+```
279307
280308将它继承:
281309
282-`property PropName: PropType read FPropName;`
310+```text
311+property PropName: PropType read FPropName;
312+```
283313
284314创建一个只写属性:
285315
286-` property PropName: PropType write;`
316+```text
317+ property PropName: PropType write;
318+```
287319
288320将它继承:
289321
290-`property PropName: PropType write SetPropName;`
322+```text
323+property PropName: PropType write SetPropName;
324+```
291325
292326创建一个只读属性与读取方法:
293327
294-`property PropName: PropType read GetPropName;`
328+```text
329+property PropName: PropType read GetPropName;
330+```
295331
296332保持和GetPropName功能:
297333
298-`function GetpropName: PropType;`
334+``` pascal
335+function GetpropName: PropType;
336+```
299337
300338创建一个属性与存储的修饰符:
301339
302-`property PropName: PropType stored;`
340+```text
341+property PropName: PropType stored;
342+```
303343
304344将它继承:
305345
306-`property PropName: PropType read FPropName write SetPropName stored PropNameIsStored;`
346+```text
347+property PropName: PropType read FPropName write SetPropName stored PropNameIsStored;
348+```
307349
308350Because stored is used for streaming read and write modifiers are automatically added as well.
309351
310352提示: 标识符完成允许不完整的属性,并且会提示的默认名称。例如:
311353
312-`property PropName: PropType read |;`
354+```text
355+property PropName: PropType read |;
356+```
313357
314358将光标置于一个空格的'读'的关键字,然后按`Ctrl`+`Space`,它会给出变量'FPropName'和过程'SetPropName“。
315359
316360### 前向引用自动完成
317361
318362前向引用自动完成是代码完成部分,用于添加缺少的过程体。当光标在一个前向定义的过程上时,
319363
320364例如: 添加一个新过程在接口部分:
321365
322-`procedure DoSomething;`
366+``` pascal
367+procedure DoSomething;
368+```
323369
324370将光标放在声明上,按`Ctrl`+`Shift`+`C`,这将创建实现部分:
325371
326-`procedure DoSomething;`\
327-`begin`\
328-`  |`\
329-`end;`
372+``` pascal
373+procedure DoSomething;
374+begin
375+ |
376+end;
377+```
330378
331379提示:你可以按`Ctrl`+`Shift`+`Up`,在过程定义与过程体间跳转。
332380
333381如果已经存在过程,新过程体将添加到类方法中,IDE试图保持有序,例如:
334382
335-` procedure Proc1;`\
336-` procedure Proc2; // 新过程`\
337-` procedure Proc3;`
383+``` pascal
384+ procedure Proc1;
385+ procedure Proc2; // 新过程
386+ procedure Proc3;
387+```
338388
339389如果Proc1和Proc3已经存在,那么Proc2部分会在Proc1和Proc3间添加。This behaviour can be setup in Environment \> Codetools Options -\> Code Creation.
340390
341391多个过程:
342392
343-`procedure Proc1_Old; // 过程体存在`\
344-`procedure Proc2_New; // 过程体不存在`\
345-`procedure Proc3_New; //  "`\
346-`procedure Proc4_New; //  "`\
347-`procedure Proc5_Old; // 过程体存在`
393+``` pascal
394+procedure Proc1_Old; // 过程体存在
395+procedure Proc2_New; // 过程体不存在
396+procedure Proc3_New; // "
397+procedure Proc4_New; // "
398+procedure Proc5_Old; // 过程体存在
399+```
348400
349401代码完成,将添加3个过程体:(Proc2_New, Proc3_New, Proc4_New)。
350402
351403为什么称它是“前向引用自动完成”?
352404
353405先了解下,[[Basic Pascal Tutorial/Chapter 4/Forward Referencing/zh CN|前向引用]]。
354406
355407Because it does not only work for procedures defined in the interface, but for procedures with the "forward" modifier as well. And because the codetools treats procedures in the interface as having an implicit 'forward' modifier.
356408
357409### 事件赋值自动完成
358410
359411事件赋值自动完成,是代码自动完成的一部分,在使用时,将光标放在要赋值事件的后面。
360412
361413例如,在FormCreate中添加一行:
362414
363-`OnPaint:=`
415+``` pascal
416+OnPaint:=
417+```
364418
365-`procedure TForm1.Form1Create(Sender: TObject);`\
366-`begin`\
367-`  OnPaint:=|`\
368-`end;`
419+``` pascal
420+procedure TForm1.Form1Create(Sender: TObject);
421+begin
422+ OnPaint:=|
423+end;
424+```
369425
370426注意:\|是光标所在位置。
371427
372428按`Ctrl`+`Shift`+`C`后,代码将会:
373429
374-`OnPaint:=@Form1Paint;`
430+``` pascal
431+OnPaint:=@Form1Paint;
432+```
375433
376434Form1Paint方法,将被添加到TForm1类中,
377435
378-`procedure TForm1.Form1Paint(Sender: TObject);`\
379-`begin`\
380-`  |`\
381-`end;`
436+``` pascal
437+procedure TForm1.Form1Paint(Sender: TObject);
438+begin
439+ |
440+end;
441+```
382442
383443这就像在对象观察器中添加方法。
384444
385445注意:\
386446你必须把光标放在:=后,但如果你将光标放在标识符后,那么将调用代码自动完成。
387447
388448提示:\
389449你可以自定义方法名,如:
390450
391-` OnPaint:=@ThePaintMethod;`
451+``` pascal
452+ OnPaint:=@ThePaintMethod;
453+```
392454
393455### 变量声明自动完成
394456
395457变量声明自动完成,将未声明的变量对它声明。
396458
397459如一个局部变量定义:
398460
399-`标识符:=值;`
461+``` pascal
462+标识符:=值;
463+```
400464
401465将光标放置在标识符后面。
402466
403467``` pascal
404468procedure TForm1.Form1Create(Sender: TObject);
405469begin
406470 i:=3;
407471end;
408472```
409473
410474将光标位在i后,按`Ctrl`+`Shift`+`C`将得到:
411475
412476``` pascal
413477procedure TForm1.Form1Create(Sender: TObject);
414478var
415479 i: Integer;
416480begin
417481 i:=3;
418482end;
419483```
420484
421485如果标识符i已经被定义,并且没有添加声明
422486
423-`var i: integer;`
487+``` pascal
488+var i: integer;
489+```
424490
425491标识符的类型,通过赋值运算来得到类型。像数字3默认为整型。
426492
427493另一个例子:
428494
429495``` pascal
430496type
431497 TWhere = (Behind, Middle, InFront);
432498
433499 procedure TForm1.Form1Create(Sender: TObject);
434500 var
435501 a: array[TWhere] of char;
436502 begin
437503 for Where:=Low(a) to High(a) do writeln(a[Where]);
438504 end;
439505```
440506
441507将光标放置在where后,按`Ctrl`+`Shift`+`C`将得到:
442508
443509``` pascal
444510 procedure TForm1.Form1Create(Sender: TObject);
445511 var
446512 a: array[TWhere] of char;
447513 Where: TWhere;
448514 begin
449515 for Where:=Low(a) to High(a) do writeln(a[Where]);
450516 end;
451517```
452518
453519lazarus 0.9.11后将会完成参数:
454520
455521``` pascal
456522 procedure TForm1.FormPaint(Sender: TObject);
457523 begin
458524 with Canvas do begin
459525 Line(x1,y1,x2,y2);
460526 end;
461527 end;
462528```
463529
464530将光标放置在x1后,按`Ctrl`+`Shift`+`C`将得到:
465531
466532``` pascal
467533 procedure TForm1.FormPaint(Sender: TObject);
468534 var
469535 x1: integer;
470536 begin
471537 with Canvas do begin
472538 Line(x1,y1,x2,y2);
473539 end;
474540 end;
475541```
476542
477543### 过程调用自动完成
478544
479545代码完成可以通过调用语句本身创建一个新程序。假设你刚编写声明
480546
481-`DoSomething(Width);`
547+```text
548+DoSomething(Width);
549+```
482550
483551``` pascal
484552procedure SomeProcedure;
485553var
486554 Width: integer;
487555begin
488556 Width:=3;
489557 DoSomething(Width);
490558end;
491559```
492560
493561将光标放在标识符DoSomething上,按`Ctrl`+`Shift`+`C`,将得到:
494562
495563``` pascal
496564procedure DoSomething(aWidth: LongInt);
497565begin
498566
499567end;
500568
501569procedure SomeProcedure;
502570var
503571 Width: integer;
504572begin
505573 Width:=3;
506574 DoSomething(Width);
507575end;
508576```
509577
510578它不会创建函数或方法。
511579
512580### 反转类自动完成
513581
514582声明当前私有方法。自Lazarus 0.9.21后可用。
515583
516584如:
517585
518-` procedure TForm1.DoSomething(Sender: TObject);`\
519-` begin`\
520-` end;`
586+``` pascal
587+ procedure TForm1.DoSomething(Sender: TObject);
588+ begin
589+ end;
590+```
521591
522592DoSomething未被声明,按`Ctrl`+`Shift`+`C`,将添加TForm1类的私有方法
523593
524-`procedure DoSomething(Sender: TObject);`
594+``` pascal
595+procedure DoSomething(Sender: TObject);
596+```
525597
526598对于 Delphians:
527599
528600Lazarus下完成工作始终是:从类接口来实现向后/反转类声明。Delphi是两个方向,但它有个缺点:让你不注意的一个错字会很容易的创建一个方法。
529601
530602### 注释和代码自动完成
531603
532604Code completion tries to keep comments where they belong. For example:
533605
534-` FList: TList; // list of TComponent`\
535-` FInt: integer;`
606+```text
607+ FList: TList; // list of TComponent
608+ FInt: integer;
609+```
536610
537611When inserting a new variable between FList and FInt, the comment is kept in the FList line. Same is true for
538612
539-` FList: TList; { list of TComponent`\
540-`   This is a comment over several lines, starting`\
541-`   in the FList line, so codetools assumes it belongs `\
542-`   to the FLIst line and will not break this `\
543-`   relationship. Code is inserted behind the comment. }`\
544-` FInt: integer;`
613+```text
614+ FList: TList; { list of TComponent
615+ This is a comment over several lines, starting
616+ in the FList line, so codetools assumes it belongs
617+ to the FLIst line and will not break this
618+ relationship. Code is inserted behind the comment. }
619+ FInt: integer;
620+```
545621
546622If the comment starts in the next line, then it will be treated as if it belongs to the code below. For example:
547623
548-` FList: TList; // list of TComponent`\
549-`   { This comment belongs to the statement below. `\
550-`     New code is inserted above this comment and `\
551-`     behind the comment of the FList line. }`\
552-` FInt: integer;`
624+```text
625+ FList: TList; // list of TComponent
626+ { This comment belongs to the statement below.
627+ New code is inserted above this comment and
628+ behind the comment of the FList line. }
629+ FInt: integer;
630+```
553631
554632### 方法更新
555633
556634通常类完成将添加缺少的方法体,自0.9.27,如果类中的方法不同,那么方法体将被更新,如你有一个DoSomething方法:
557635
558636``` pascal
559637public
560638 procedure DoSomething;
561639end;
562640
563641procedure TForm.DoSomething;
564642begin
565643end;
566644```
567645
568646添加一个参数:
569647
570648``` pascal
571649 public
572650 procedure DoSomething(i: integer);
573651 end;
574652```
575653
576654按`Ctrl`+`Shift`+`C`,该方法声明将被更新,新的参数将被更新:
577655
578656``` pascal
579657procedure TForm.DoSomething(i: integer);
580658begin
581659end;
582660```
583661
584662## 重构
585663
586664### 互换指派
587665
588666"Invert Assignments" takes some selected pascal statements and inverts all assignments from this code. This tool is usefull for transforming a "save" code to a "load" one and inverse operation. ~~摘要:互换指派,将某些选定的Pascal语句互换。~~
589667
590668如:\
591-procedure DoSomething;
592669
593-`begin`\
594-`  AValueStudio:= BValueStudio;`\
595-`  AValueAppartment :=BValueAppartment;`\
596-`  AValueHouse:=BValueHouse;`\
597-`end;`
670+``` pascal
671+procedure DoSomething;
672+begin
673+ AValueStudio:= BValueStudio;
674+ AValueAppartment :=BValueAppartment;
675+ AValueHouse:=BValueHouse;
676+end;
677+```
598678
599679选择要反转的代码,右击选择重构-\>互换指派”。(或者,Source菜单-\>重构-\>互换指派)。
600680
601681结果:
602682
603-`procedure DoSomething;`\
604-`begin`\
605-`  BValueStudio     := AValueStudio;`\
606-`  BValueAppartment := AValueAppartment;`\
607-`  BValueHouse      := AValueHouse;`\
608-`end;`
683+``` pascal
684+procedure DoSomething;
685+begin
686+ BValueStudio := AValueStudio;
687+ BValueAppartment := AValueAppartment;
688+ BValueHouse := AValueHouse;
689+end;
690+```
609691
610692### 封装所选
611693
612694选择一些内容,按`Ctrl`+`Shift`+`N`,会弹出一个对话框,你可以选择一项,之后,会将所选择的内容,括住。
613695
614696如,你选择了try..finally项,那么,你选择的内容将会被try..finally括住。
615697
616698你可以在选择内容上右击,源代码-\>封装所选;或者,Source菜单-\>封装所选,都可以实现此功能。
617699
618700### 重命名标识符
619701
620702将光标放在标识符上,并调用它(按`F2`,或右击重构-\>重命名标识符;也可以在Source菜单-\>重构-\>重命名标识符)。
621703
622704将弹出对话框,输入新的标识符名称,设置搜索范围。
623705
624706- It will rename all occurences and only those that actually use this declaration. That means it does not rename declarations with the same name.
625707- ~~它将重命名所有出现,只有那些真正使用这个声明。这意味着它不重命名声明名称相同的。~~
626708- And it will first check for name conflicts.
627709- ~~它将首先检查名称冲突。~~
628710- Limits: It only works on pascal sources, does not yet rename files nor adapt lfm/lrs files nor lazdoc files.
629711- ~~限制:它仅适用于Pascal源文件,还没有重命名的文件,不适用LFM/LRS文件,也不适用,lazdoc文件。~~
630712
631713### 查找标识符参考
632714
633715将光标放在标识符上,并调用它(按`Ctrl`+`Shift`+`I`,或右击查找-\>查找标识符参考;也可以在查找菜单-\>查找标识符参考);
634716
635717在出现的对话框中设置搜索范围,IDE将搜索所有出现的,只有那些真正使用这一标识符的,意味着不会显示相同名称的。
636718
637719### 显示抽象方法
638720
639721This feature lists and auto completes virtual, abstracts methods that need to be implemented. Place the cursor on a class declaration and invoke it. If there are missing abstract methods a dialog will appear listing them. Select the methods to implement and the IDE creates the method stubs.
640722
641723### 抽取过程
642724
643725查看 [[IDE Window: Extract Procedure/zh CN|抽取过程]]
644726
645727## 查找声明
646728
647729将光标定位在要查找声明的标识符上,右击选择查找声明。之后,将搜索并跳转到所选择标识符的定义部分。
648730
649731Every find declaration sets a Jump Point. That means you jump with find declaration to the declaration and easily jump back with Search -\> Jump back.
650732
651733在Delphi上有些不同:
652734
653735The codetools work on sources following the normal pascal rules, instead of using the compiler output. The compiler returns the final type. The codetools see the sources and all steps in between. For example:
654736
655737The *Visible* property is first defined in TControl (controls.pp), then redefined in TCustomForm and finally redefined in TForm. Invoking find declaration on Visible will you first bring to Visible in TForm. Then you can invoke Find Declaration again to jump to Visible in TCustomForm and again to jump to Visible in TControl.
656738
657739~~*可见*属性是在TControl (controls.pp)中定义的,然后重新定义TCustomForm在TForm。查找声明时,首先找到TForm,之后再查找时会跳转找到TControl。~~
658740
659741像TColor类型,对于编译器它是一个简单的'longint'类型,但在源中其定义是:
660742
661-`TGraphicsColor = -$7FFFFFFF-1..$7FFFFFFF;`\
662-`TColor = TGraphicsColor;`
743+```text
744+TGraphicsColor = -$7FFFFFFF-1..$7FFFFFFF;
745+TColor = TGraphicsColor;
746+```
663747
664748和*前向定义类*类似,如TControl中,有一个私有变量
665749
666-`FHostDockSite: TWinControl;`
750+```text
751+FHostDockSite: TWinControl;
752+```
667753
668754查找声明TWinControl,将跳到前向定义。
669755
670-`TWinControl = class;`
756+```text
757+TWinControl = class;
758+```
671759
672760之后再跳转到真正实现部分
673761
674-`TWinControl = class(TControl)`
762+```text
763+TWinControl = class(TControl)
764+```
675765
676766这样你就可以跟踪每个标识符或查找负载。
677767
678768**提示:**
679769
680770- 按 `Ctrl`+`H` 跳回来
681771- 查看所有跳转历史:查看菜单-\>查看跳转历史
682772- With a 5 button Mouse you can use the 2 extra buttons to go forward/backward between the visited points
683773- ~~用5键鼠标,可以使用2个额外的按钮来实现前进/后退光标位置~~
684774
685775
686776(你可以使用[[IDE Window: EditorMouseOptionsAdvanced|高级鼠标选项]]来映射)
687777
688778## 标识符自动完成
689779
690780按`Ctrl`+`space`调用标识符自动完成,它将显示范围内的所有标识符提示。如:
691781
692-` procedure TForm1.FormCreate(Sender: TObject);`\
693-` begin`\
694-`   |`\
695-` end;`
782+``` pascal
783+ procedure TForm1.FormCreate(Sender: TObject);
784+ begin
785+ |
786+ end;
787+```
696788
697789在begin和end间按`Ctrl`+`space`,IDE将分析你的代码,显示所有标识符列表。结果会被缓存,第二次调用时会很快。
698790
699791**Delphians注意:**:Delphi称为代码完成。
700792
701793像这些标识符'Write', 'ReadLn', 'Low', 'SetLength', 'Self', 'Result', 'Copy'等被内置到编译器里。 The identifier completion has a lot of these things built in as well. If you find one missing, just create a feature request in the bug tracker.
702794
703795标识符自动完成,并没有完成所有关键字。所以,人不能用它来完成repe到repeat。对于这些你可以按`Ctrl`+`W`[[Lazarus IDE Tools/zh CN|关键字自动完成]] 或 `Ctrl`+`J` [[Lazarus IDE Tools/zh CN|代码模板]]。
704796
705797自0.9.27后,标识符自动完成了,完成了些关键字。
706798
707799Identifier completion shows even those identifiers, that are not compatible.
708800
709801### 前缀
710802
711803你可以使用一个单词或字母做为前缀,比如说:
712804
713-` procedure TForm1.FormCreate(Sender: TObject);`\
714-` begin`\
715-`   Ca|ption`\
716-` end;`
805+``` pascal
806+ procedure TForm1.FormCreate(Sender: TObject);
807+ begin
808+ Ca|ption
809+ end;
810+```
717811
718812在Ca后使用标识符自动完成,将显示所有ca开头的标识符列表。
719813
720814### 键
721815
722816- 字母或数字:字符添加到源代码编辑器作为前缀,这将更新列表。
723817- 退格键:从前缀中删除一个字符,这将更新列表。
724818- Return: replace the whole word at cursor with the selected identifier and close the popup window.
725819- Shift+Return: as *Return*, but replaces only the prefix (left part) of the word at the cursor.
726820- 上/下键: 移动选择。
727821- ESC键: 不保存信息,关闭弹出对话框。
728822- Tab: completes the prefix to next choice. For example: The current prefix is 'But' and the identifier completion only shows 'Button1' and 'Button1Click'. Then pressing *Tab* will complete the prefix to 'Button1'.
729823- Else: as *Return* and add the character to the source editor
730824
731825### 方法
732826
733827当光标在类中定义方法时,使用标识符自动完成会添加相应参数并添加override关键字。例如:
734828
735829``` pascal
736830TMainForm = class(TForm)
737831protected
738832 mous|
739833end;
740834```
741835
742836完成的**MouseDown**:
743837
744838``` pascal
745839TMainForm = class(TForm)
746840protected
747841 procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X,
748842 Y: Integer); override;
749843end;
750844```
751845
752846### 属性
753847
754848``` pascal
755849property MyInt: integer read |;
756850```
757851
758852标识符自动完成,将显示**FMyInt**和**GetMyInt**。
759853
760854``` pascal
761855property MyInt: integer write |;
762856```
763857
764858标识符自动完成,将显示**FMyInt**和**SetMyInt**。
765859
766860### 引用部分/单元名称
767861
768862In uses sections the identifier completion will show the filenames of all units in the search path. These will show all lowercase (e.g. **avl_tree**), because most units have lowercase filenames. On completion it will insert the nice case of the unit (e.g. **AVL_Tree**).
769863
770864~~引用某些单元文件时,使用标识符自动完成,将显示它们的文件路径,文件名通常是小写的(像**avl_tree**),完成后,会插入像**AVL_Tree**一样的名称。~~
771865
772866### 语句
773867
774868``` pascal
775869procedure TMainForm.Button1Click(Sender: TObject);
776870begin
777871 ModalRe|;
778872end;
779873```
780874
781875变为:
782876
783877``` pascal
784878procedure TMainForm.Button1Click(Sender: TObject);
785879begin
786880 ModalResult:=|;
787881end;
788882```
789883
790884## 关键字自动完成
791885
792886按`Ctrl`+`W`键调用关键词自动完成。它显示了当前打开文件中的匹配到的关键词,你也可以在非Pascal源文件中使用,在注释中也可以使用。
793887
794888否则,它的工作方式等同于标识符自动完成。
795889
796890## Goto Include Directive
797891
798892"Goto Include Directive" in the search menu of the IDE jumps to {\$I filename} statement where the current include file is used.
799893
800894## 发布工程
801895
802896创建项目副本。If you want to send someone just the sources and compiler settings of your code, this function is your friend.
803897
804898一个项目目录包含了大量信息,很多是不需要再作公布:lpi文件包含了会话信息(像光标位置 、单元书签),项目目录包含了ppu、o及可执行文件。
805899
806900要发布工程,在工程菜单下使用发布工程。
807901
808902**注**:0.9.13版本后,有了新的解决方法,它将会话信息存储在了以lps为扩展名的文件里,这样,当你发布时,lpi文件会清爽很多。
809903
810904在对话框中你可以设置排除列表和过滤器,也可以完成后使用命令压缩成一个档案。
811905
812906## 注释提示
813907
814908在某些地方IDE将显示帮助提示。如,将鼠标移动在一个标识符上等待几秒钟,将显示与此标识符相关的提示信息。
815909
816910IDE为了支持常见的注释、编程风格,通常会给予试探:
817911
818912### 显示注释提示
819913
820914注释声明中以**\<**开头(没有空行),将作为其上的提示:
821915
822916``` pascal
823917var
824918 {Comment}
825919 Identifier: integer;
826920```
827921
828922注释在**\<**之后。
829923
830924与标识符同行的注释:
831925
832926``` pascal
833927var
834928 identifier, // Comment
835929 other,
836930```
837931
838932注释和定义在同一行:
839933
840934``` pascal
841935var
842936 identifier:
843937 char; // Comment
844938```
845939
846940**\<**示例:
847941
848942``` pascal
849943const
850944 a = 1;
851945 //< comment for a
852946 b = 2;
853947 // comment for c
854948 c = 3;
855949```
856950
857951支持三种注释方式
858952
859953``` pascal
860954 {Comment}(*Comment*)//Comment
861955 c = 1;
862956```
863957
864958注释中**\$**和**%**将被忽略。
865959
866960### 不显示注释信息
867961
868962用空行分隔的注释,将不会用于提示显示。像下面的类头部注释将不会被显示:
869963
870964``` pascal
871965type
872966 { TMyClass }
873967
874968 TMyClass = class
875969```
876970
877971类头部注释创建于类完成时。你可以关闭这个功能:在工具菜单-\>选项中,代码工具-\>Class completion-\>类的头注释。 如果你想显示这些提示,删除空行即可。
878972
879973下面的注释,GL_TRUE将会显示提示,GL_FALSE不会:
880974
881975``` pascal
882976 // Boolean
883977 GL_TRUE = 1;
884978 GL_FALSE = 0;
885979```
886980
887981---
888982*From the Free Pascal wiki, page "Lazarus IDE Tools/zh CN", as it stood on 2023-01-25 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