Sign in Join
Wiki copytemporary

Lazarus IDE Tools/zh CN: what changed

Revision 1 to 2. 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|----|----|
13-| [[Lazarus IDE Tools/zh CN|查找声明]] | <span class="kbd">Ctrl</span>+点击 or <span class="kbd">Alt</span>+<span class="kbd">Up</span> (跳转到声明的类型或变量) |
14-| [[Lazarus IDE Tools/zh CN|方法跳转]] | <span class="kbd">Ctrl</span>+<span class="kbd">Shift</span>+<span class="kbd">Up</span> (在定义部分和实现部分进行切换。看见一个定义,就可以用快键方式,直接找到它的实现部分。) |
15-| [[Lazarus IDE Tools/zh CN|代码模板]] | <span class="kbd">Ctrl</span>+<span class="kbd">J</span> |
16-| [[Lazarus IDE Tools/zh CN|Syncro 编辑(同步编辑)]] | <span class="kbd">Ctrl</span>+<span class="kbd">J</span> (需要选择文本) |
17-| [[Lazarus IDE Tools/zh CN|类自动完成]] | <span class="kbd">Ctrl</span>+<span class="kbd">Shift</span>+<span class="kbd">C</span> |
18-| [[Lazarus IDE Tools/zh CN|标识符自动完成]] | <span class="kbd">Ctrl</span>+<span class="kbd">空格</span> |
19-| [[Lazarus IDE Tools/zh CN|关键字自动完成]] | <span class="kbd">Ctrl</span>+<span class="kbd">W</span> |
20-| [[Lazarus IDE Tools/zh CN|参数提示]] | <span class="kbd">Ctrl</span>+<span class="kbd">Shift</span>+<span class="kbd">空格</span> |
21-| [[Lazarus IDE Tools/zh CN|渐进式搜索]] | <span class="kbd">Ctrl</span>+<span class="kbd">E</span> |
13+| [[Lazarus IDE Tools/zh CN|查找声明]] | `Ctrl`+点击 or `Alt`+`Up` (跳转到声明的类型或变量) |
14+| [[Lazarus IDE Tools/zh CN|方法跳转]] | `Ctrl`+`Shift`+`Up` (在定义部分和实现部分进行切换。看见一个定义,就可以用快键方式,直接找到它的实现部分。) |
15+| [[Lazarus IDE Tools/zh CN|代码模板]] | `Ctrl`+`J` |
16+| [[Lazarus IDE Tools/zh CN|Syncro 编辑(同步编辑)]] | `Ctrl`+`J` (需要选择文本) |
17+| [[Lazarus IDE Tools/zh CN|类自动完成]] | `Ctrl`+`Shift`+`C` |
18+| [[Lazarus IDE Tools/zh CN|标识符自动完成]] | `Ctrl`+`空格` |
19+| [[Lazarus IDE Tools/zh CN|关键字自动完成]] | `Ctrl`+`W` |
20+| [[Lazarus IDE Tools/zh CN|参数提示]] | `Ctrl`+`Shift`+`空格` |
21+| [[Lazarus IDE Tools/zh CN|渐进式搜索]] | `Ctrl`+`E` |
2222
2323## 方法跳转
2424
25-要在过程体(begin..end)与过程定义(procedure 过程名)间跳转,使用 <span class="kbd">Ctrl</span>+<span class="kbd">Shift</span>+<span class="kbd">Up</span>.
25+要在过程体(begin..end)与过程定义(procedure 过程名)间跳转,使用 `Ctrl`+`Shift`+`Up`.
2626
2727示例:
2828
2929`interface`\
30-\
30+
3131`procedure DoSomething; // 过程定义`\
3232` `\
3333`implementation`\
3434` `\
3535`procedure DoSomething; // 过程体`\
3636`begin`\
3737`end;`
3838
39-如果光标在过程体,当你按<span class="kbd">Ctrl</span>+<span class="kbd">Shift</span>+<span class="kbd">Up</span>时,会跳转到其定义,再次按<span class="kbd">Ctrl</span>+<span class="kbd">Shift</span>+<span class="kbd">Up</span>会跳转到过程体;如此循环。
39+如果光标在过程体,当你按`Ctrl`+`Shift`+`Up`时,会跳转到其定义,再次按`Ctrl`+`Shift`+`Up`会跳转到过程体;如此循环。
4040
4141在方法间(类中的过程)也是如此。
4242
4343注意: *方法跳转*,将跳转到具有相同名称和参数列表的地方,如果没有,它将跳到最佳匹配的地方,并将光标定位在第一个上面。(对于Delphians:Delphi不能做到这一点。)
4444
4545例如,不同参数类型的过程:
4646
4747`interface`\
48-\
48+
4949`procedure DoSomething(p: char); // 过程定义`\
50-\
50+
5151`implementation`\
5252`  `\
5353`procedure DoSomething(p: string); // 过程主体`\
5454`begin`\
5555`end;`
5656
5757自定义跳转会在'string'处定位光标,这可用于重命名方法或改变参数。
5858
5959如:\
6060你更名'DoSomething' 为 'MakeIt':
6161
6262`interface`\
63-\
63+
6464`procedure MakeIt; // 过程定义`\
65-\
65+
6666`implementation`\
67-\
67+
6868`procedure DoSomething; // 过程主体`\
6969`begin`\
7070`end;`
7171
7272Then 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.
7373
7474## 引入文件
7575
7676引入文件是使用{\$I 文件名} 或 {\$INCLUDE 文件名}编译指令。Lazarus和FPC大量采用它,以减少冗余,为考虑平台兼容性,可以使用{\$IFDEF}结构。
7777
7878Contrary 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.
7979
8080For 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.
8181
8282But 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.
8383
8484As 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
8585
8686`{%mainunit yourunit.pas} `
8787
8888on the top of yourinclude.inc.
8989
9090This mechanism has of course limits. Some include files are included twice or more. For example: lcl/include/winapih.inc.
9191
9292Jumping 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. ;)
9393
9494## 代码模板
9595
9696代码模板将标识符转换为文本或代码片段。
9797
98-默认快捷键是<span class="kbd">Ctrl</span>+<span class="kbd">J</span>。输入一个标识符,之后按<span class="kbd">Ctrl</span>+<span class="kbd">J</span>键将会替换该标识符为选定的内容。代码模板可以在“工具”菜单-\>“选项“-\>“代码工具”里设置。
98+默认快捷键是`Ctrl`+`J`。输入一个标识符,之后按`Ctrl`+`J`键将会替换该标识符为选定的内容。代码模板可以在“工具”菜单-\>“选项“-\>“代码工具”里设置。
9999
100-如,在标识符<strong>classf</strong>后按<span class="kbd">Ctrl</span>+<span class="kbd">J</span>,<strong>classf</strong>将被替换为:
100+如,在标识符classf后按`Ctrl`+`J`,classf将被替换为:
101101
102102`T = class(T)`\
103103`private`\
104-\
104+
105105`public`\
106106`  constructor Create;`\
107107`  destructor Destroy; override;`\
108108`end;`
109109
110-并且光标在<strong>T</strong>后面。你可以将光标定位在空白位置(而不是标识符那里),按下 <span class="kbd">Ctrl</span>+<span class="kbd">J</span>键,将显示代码模板列表。选择一个,将返回选择的代码模板。
110+并且光标在T后面。你可以将光标定位在空白位置(而不是标识符那里),按下 `Ctrl`+`J`键,将显示代码模板列表。选择一个,将返回选择的代码模板。
111111
112-输入<strong>b</strong>之后,按<span class="kbd">Ctrl</span>+<span class="kbd">J</span>键,将显示 <strong>begin..end;</strong> 块。
112+输入b之后,按`Ctrl`+`J`键,将显示 begin..end; 块。
113113
114114## 参数提示
115115
116116显示参数提示。
117117
118118例如:
119119
120120`Canvas.FillRect();`
121121
122-将光标置于括号中,按<span class="kbd">Ctrl</span>+<span class="kbd">Shift</span>+<span class="kbd">space</span>键,将显示FillRect的参数提示信息。
122+将光标置于括号中,按`Ctrl`+`Shift`+`space`键,将显示FillRect的参数提示信息。
123123
124124## 渐进式搜索
125125
126-渐进式搜索,按<span class="kbd">Ctrl</span>+<span class="kbd">E</span>,输入搜索的文本,编辑器会高亮所有搜索到的。
126+渐进式搜索,按`Ctrl`+`E`,输入搜索的文本,编辑器会高亮所有搜索到的。
127127
128-- 例如,输入<span class="kbd">e</span>,将搜索并高亮显示所有<strong>e</strong>的匹配项。
129-- 然后,输入<span class="kbd">t</span> ,将突出显示所有匹配<strong>et</strong>的文本。
130-- 跳转到下一个匹配项,按 <span class="kbd">F3</span>或(<span class="kbd">Ctrl</span>+<span class="kbd">E</span>);跳转到上一匹配项,按<span class="kbd">Shift</span>+<span class="kbd">F3</span>。
131-- <span class="kbd">Backspace</span> 删除最后一个字符。
132-- 停止搜索,可以按<span class="kbd">Enter</span>键,或者在代码编辑器中点击鼠标。
133-- You can resume the last search by pressing <span class="kbd">Ctrl</span>+<span class="kbd">e</span> a second time, immediately after you started incr-search with <span class="kbd">Ctrl</span>+<span class="kbd">e</span>. that is while the search term is still empty.
134-- <span class="kbd">Ctrl</span>+<span class="kbd">V</span>键,粘贴剪贴板中的内容到当前搜索(因为lazarus 0.9.27 r19824)。
128+- 例如,输入`e`,将搜索并高亮显示所有e的匹配项。
129+- 然后,输入`t` ,将突出显示所有匹配et的文本。
130+- 跳转到下一个匹配项,按 `F3`或(`Ctrl`+`E`);跳转到上一匹配项,按`Shift`+`F3`。
131+- `Backspace` 删除最后一个字符。
132+- 停止搜索,可以按`Enter`键,或者在代码编辑器中点击鼠标。
133+- 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.
134+- `Ctrl`+`V`键,粘贴剪贴板中的内容到当前搜索(因为lazarus 0.9.27 r19824)。
135135
136136### 注意:快速搜索与渐进式搜索的标识符
137137
138138- Place text cursor on identifier (do not select anything) ~~将光标放在标识符处(不要选择任何内容)。~~
139-- 按<span class="kbd">Ctrl</span>+<span class="kbd">C</span>键,将复制选择的标识符到剪贴板。
140-- 按<span class="kbd">Ctrl</span>+<span class="kbd">E</span>键,开始渐进式搜索。
141-- 按<span class="kbd">Ctrl</span>+<span class="kbd">V</span>键,搜索标识符(自0.9.27)。
142-- <span class="kbd">F3</span>,向下搜索,<span class="kbd">Shift</span>+<span class="kbd">F3</span>向下搜索。
139+- 按`Ctrl`+`C`键,将复制选择的标识符到剪贴板。
140+- 按`Ctrl`+`E`键,开始渐进式搜索。
141+- 按`Ctrl`+`V`键,搜索标识符(自0.9.27)。
142+- `F3`,向下搜索,`Shift`+`F3`向下搜索。
143143- 使用任意键(如,光标左、右键)来终止搜索。
144144
145145## Syncro 编辑(同步编辑)
146146
147147Syncro Edit(同步编辑)可以让你在同一时间同步编辑所有匹配到的内容。你简单的在一个地方编辑,所有匹配的内容也会同步更新。
148148
149149它适用于所有选择区域的文本:
150150
151151- 选择文本块。
152-- 按<span class="kbd">Ctrl</span>+<span class="kbd">J</span>或,点击编辑左侧显示的“编辑图标”(![](/wiki-images/7/7e/SyncroEditIcon.png))。按<span class="kbd">tab</span>键,选择要编辑的内容。
152+- 按`Ctrl`+`J`或,点击编辑左侧显示的“编辑图标”(![](/wiki-images/7/7e/SyncroEditIcon.png))。按`tab`键,选择要编辑的内容。
153153- 输入新内容。
154-- 按<span class="kbd">Esc</span>键完成编辑。
154+- 按`Esc`键完成编辑。
155155
156156这里有[[New IDE features since|动画演示]]。
157157
158-> **Note:** <span class="kbd">Ctrl</span>+<span class="kbd">J</span>也是代码模板的快捷键,如果你选择的不是文本块的话。
158+> **Note:** `Ctrl`+`J`也是代码模板的快捷键,如果你选择的不是文本块的话。
159159
160160## 查找下一个/上一个出现的单词
161161
162162这两个功能,可以在源代码编辑器的弹出菜单中找到:
163163
164164- 源代码编辑器 / 弹出菜单 / 查找 / 查找下一个发现的词
165165- 源代码编辑器 / 弹出菜单 / 查找 / 查找前一个发现的词
166166
167167And you can assign them shortcuts in the editor options.~~你也可以在查找菜单中,找到相应菜单项,它与其功能相同,当然也可以使用快捷键。~~
168168
169169## 代码自动完成
170170
171-代码自动完成,可以在“编辑”菜单-\>“自动完成代码”,或按<span class="kbd">Ctrl</span>+<span class="kbd">Shift</span>+<span class="kbd">C</span>键。(新版的Lazarus,在“Source”菜单-\>“自动完成代码”)
171+代码自动完成,可以在“编辑”菜单-\>“自动完成代码”,或按`Ctrl`+`Shift`+`C`键。(新版的Lazarus,在“Source”菜单-\>“自动完成代码”)
172172
173173对于Delphians:
174174
175-Delphi的“代码完成”,按<span class="kbd">Ctrl</span>+<span class="kbd">Space</span>将显示标识符列表。在Lazarus中称为“标识符提示”。
175+Delphi的“代码完成”,按`Ctrl`+`Space`将显示标识符列表。在Lazarus中称为“标识符提示”。
176176
177177代码自动完成,有多种强大功能:
178178
179179- 类完成:自动完成属性,在方法体中增加/更新私有变量或私有方法。
180180- [[Basic Pascal Tutorial/Chapter 4/Forward Referencing/zh CN|前向引用]]过程完成: 添加过程体。
181181- 事件赋值完成:完成事件赋值,并增加了方法定义和主体。
182182- 变量声明完成:增加了局部变量定义。
183183- 过程调用完成:添加新过程。
184184- 反转过程完成:添加过程/函数体声明。
185185- 反转类完成:添加了方法体声明。
186186
187187这个功能的使用,取决于编辑器中光标的位置,下面进行说明。
188188
189189### 类自动完成
190190
191-<strong>(翻译不完善不完整,需要修订)</strong>
191+(翻译不完善不完整,需要修订)
192192
193193“类完成”是代码完成中最强大的,编写一个类,添加方法和属性,代码完成,将添加方法休,属性访问方法和变量。
194194
195195如,创建一个类(见代码模板,以节省你的工作时间):
196196
197197`TExample = class(TObject)`\
198198`public`\
199199`  constructor Create;`\
200200`  destructor Destroy; override;`\
201201`end;`
202202
203-在类中,按<span class="kbd">Ctrl</span>+<span class="kbd">Shift</span>+<span class="kbd">C</span>键,将会创建缺少的方法,并将光标移到创建的第一个方法体中,所以,你可以开始编写类代码:
203+在类中,按`Ctrl`+`Shift`+`C`键,将会创建缺少的方法,并将光标移到创建的第一个方法体中,所以,你可以开始编写类代码:
204204
205205`{ TExample }`\
206-\
206+
207207`constructor TExample.Create;`\
208208`begin`\
209209`  |`\
210210`end;`\
211-\
211+
212212`destructor TExample.Destroy;`\
213213`begin`\
214214`  inherited Destroy;`\
215215`end;`
216216
217217留意: '\|'是光标位置。
218218
219-提示:你可以按按<span class="kbd">Ctrl</span>+<span class="kbd">Shift</span>+<span class="kbd">Up</span>键,在方法与方法体间跳转。
219+提示:你可以按按`Ctrl`+`Shift`+`Up`键,在方法与方法体间跳转。
220220
221-你可以看到,在IDE中加入了<strong>继承销毁</strong>,因为,在类中定义了<strong>override</strong>关键字。
221+你可以看到,在IDE中加入了继承销毁,因为,在类中定义了override关键字。
222222
223223现在,添加一个DoSomething方法:
224224
225225`TExample = class(TObject)`\
226226`public`\
227227`  constructor Create;`\
228228`  procedure DoSomething(i: integer);`\
229229`  destructor Destroy; override;`\
230230`end;`
231231
232-按<span class="kbd">Ctrl</span>+<span class="kbd">Shift</span>+<span class="kbd">C</span>,将添加:
232+按`Ctrl`+`Shift`+`C`,将添加:
233233
234234`procedure TExample.DoSomething(i: integer);`\
235235`begin`\
236236`  |`\
237237`end;`
238238
239239你可以看到新的方法体中插入了创建和销毁,因为在类中已经定义。You can define the insertion policy in Environment \> Codetools Options -\> Code Creation.
240240
241241**完成属性** 添加一个AnInteger属性:
242242
243243`TExample = class(TObject)`\
244244`public`\
245245`  constructor Create;`\
246246`  procedure DoSomething(i: integer);`\
247247`  destructor Destroy; override;`\
248248`  property AnInteger: Integer;`\
249249`end;`
250250
251-按<span class="kbd">Ctrl</span>+<span class="kbd">Shift</span>+<span class="kbd">C</span>将得到:
251+按`Ctrl`+`Shift`+`C`将得到:
252252
253253`procedure TExample.SetAnInteger(const AValue: integer);`\
254254`begin`\
255255`  |if FAnInteger=AValue then exit;`\
256256`  FAnInteger:=AValue;`\
257257`end;`
258258
259-代码完成增加了一个写访问修饰符,并增加了一些常代码,跳转到类,按<span class="kbd">Ctrl</span>+<span class="kbd">Shift</span>+<span class="kbd">Up</span>:
259+代码完成增加了一个写访问修饰符,并增加了一些常代码,跳转到类,按`Ctrl`+`Shift`+`Up`:
260260
261261`TExample = class(TObject)`\
262262`private`\
263263`  FAnInteger: integer;`\
264264`  procedure SetAnInteger(const AValue: integer);`\
265265`public`\
266266`  constructor Create;`\
267267`  procedure DoSomething(i: integer);`\
268268`  destructor Destroy; override;`\
269269`  property AnInteger: integer read FAnInteger write SetAnInteger;`\
270270`end;`
271271
272272该属性继承了一个读取和写入访问修饰符,这个类得到了一个新的private(私有)变量FAnInteger和SetAnInteger方法。
273273
274274It 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.
275275
276276创建一个只读属性:
277277
278278`property PropName: PropType read;`
279279
280280将它继承:
281281
282282`property PropName: PropType read FPropName;`
283283
284284创建一个只写属性:
285285
286286` property PropName: PropType write;`
287287
288288将它继承:
289289
290290`property PropName: PropType write SetPropName;`
291291
292292创建一个只读属性与读取方法:
293293
294294`property PropName: PropType read GetPropName;`
295295
296296保持和GetPropName功能:
297297
298298`function GetpropName: PropType;`
299299
300300创建一个属性与存储的修饰符:
301301
302302`property PropName: PropType stored;`
303303
304304将它继承:
305305
306306`property PropName: PropType read FPropName write SetPropName stored PropNameIsStored;`
307307
308308Because stored is used for streaming read and write modifiers are automatically added as well.
309309
310310提示: 标识符完成允许不完整的属性,并且会提示的默认名称。例如:
311311
312312`property PropName: PropType read |;`
313313
314-将光标置于一个空格的'读'的关键字,然后按<span class="kbd">Ctrl</span>+<span class="kbd">Space</span>,它会给出变量'FPropName'和过程'SetPropName“。
314+将光标置于一个空格的'读'的关键字,然后按`Ctrl`+`Space`,它会给出变量'FPropName'和过程'SetPropName“。
315315
316316### 前向引用自动完成
317317
318318前向引用自动完成是代码完成部分,用于添加缺少的过程体。当光标在一个前向定义的过程上时,
319319
320320例如: 添加一个新过程在接口部分:
321321
322322`procedure DoSomething;`
323323
324-将光标放在声明上,按<span class="kbd">Ctrl</span>+<span class="kbd">Shift</span>+<span class="kbd">C</span>,这将创建实现部分:
324+将光标放在声明上,按`Ctrl`+`Shift`+`C`,这将创建实现部分:
325325
326326`procedure DoSomething;`\
327327`begin`\
328328`  |`\
329329`end;`
330330
331-提示:你可以按<span class="kbd">Ctrl</span>+<span class="kbd">Shift</span>+<span class="kbd">Up</span>,在过程定义与过程体间跳转。
331+提示:你可以按`Ctrl`+`Shift`+`Up`,在过程定义与过程体间跳转。
332332
333333如果已经存在过程,新过程体将添加到类方法中,IDE试图保持有序,例如:
334334
335335` procedure Proc1;`\
336336` procedure Proc2; // 新过程`\
337337` procedure Proc3;`
338338
339339如果Proc1和Proc3已经存在,那么Proc2部分会在Proc1和Proc3间添加。This behaviour can be setup in Environment \> Codetools Options -\> Code Creation.
340340
341341多个过程:
342342
343343`procedure Proc1_Old; // 过程体存在`\
344344`procedure Proc2_New; // 过程体不存在`\
345345`procedure Proc3_New; //  "`\
346346`procedure Proc4_New; //  "`\
347347`procedure Proc5_Old; // 过程体存在`
348348
349349代码完成,将添加3个过程体:(Proc2_New, Proc3_New, Proc4_New)。
350350
351351为什么称它是“前向引用自动完成”?
352352
353353先了解下,[[Basic Pascal Tutorial/Chapter 4/Forward Referencing/zh CN|前向引用]]。
354354
355355Because 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.
356356
357357### 事件赋值自动完成
358358
359359事件赋值自动完成,是代码自动完成的一部分,在使用时,将光标放在要赋值事件的后面。
360360
361361例如,在FormCreate中添加一行:
362362
363363`OnPaint:=`
364364
365365`procedure TForm1.Form1Create(Sender: TObject);`\
366366`begin`\
367367`  OnPaint:=|`\
368368`end;`
369369
370-注意:<strong>\|</strong>是光标所在位置。
370+注意:\|是光标所在位置。
371371
372-按<span class="kbd">Ctrl</span>+<span class="kbd">Shift</span>+<span class="kbd">C</span>后,代码将会:
372+按`Ctrl`+`Shift`+`C`后,代码将会:
373373
374374`OnPaint:=@Form1Paint;`
375375
376376Form1Paint方法,将被添加到TForm1类中,
377377
378378`procedure TForm1.Form1Paint(Sender: TObject);`\
379379`begin`\
380380`  |`\
381381`end;`
382382
383383这就像在对象观察器中添加方法。
384384
385385注意:\
386-你必须把光标放在<strong>:=</strong>后,但如果你将光标放在标识符后,那么将调用代码自动完成。
386+你必须把光标放在:=后,但如果你将光标放在标识符后,那么将调用代码自动完成。
387387
388388提示:\
389389你可以自定义方法名,如:
390390
391391` OnPaint:=@ThePaintMethod;`
392392
393393### 变量声明自动完成
394394
395395变量声明自动完成,将未声明的变量对它声明。
396396
397397如一个局部变量定义:
398398
399399`标识符:=值;`
400400
401401将光标放置在标识符后面。
402402
403403``` pascal
404404procedure TForm1.Form1Create(Sender: TObject);
405405begin
406406 i:=3;
407407end;
408408```
409409
410-将光标位在<strong>i</strong>后,按<span class="kbd">Ctrl</span>+<span class="kbd">Shift</span>+<span class="kbd">C</span>将得到:
410+将光标位在i后,按`Ctrl`+`Shift`+`C`将得到:
411411
412412``` pascal
413413procedure TForm1.Form1Create(Sender: TObject);
414414var
415415 i: Integer;
416416begin
417417 i:=3;
418418end;
419419```
420420
421-如果标识符<strong>i</strong>已经被定义,并且没有添加声明
421+如果标识符i已经被定义,并且没有添加声明
422422
423423`var i: integer;`
424424
425425标识符的类型,通过赋值运算来得到类型。像数字3默认为整型。
426426
427427另一个例子:
428428
429429``` pascal
430430type
431431 TWhere = (Behind, Middle, InFront);
432432
433433 procedure TForm1.Form1Create(Sender: TObject);
434434 var
435435 a: array[TWhere] of char;
436436 begin
437437 for Where:=Low(a) to High(a) do writeln(a[Where]);
438438 end;
439439```
440440
441-将光标放置在<strong>where</strong>后,按<span class="kbd">Ctrl</span>+<span class="kbd">Shift</span>+<span class="kbd">C</span>将得到:
441+将光标放置在where后,按`Ctrl`+`Shift`+`C`将得到:
442442
443443``` pascal
444444 procedure TForm1.Form1Create(Sender: TObject);
445445 var
446446 a: array[TWhere] of char;
447447 Where: TWhere;
448448 begin
449449 for Where:=Low(a) to High(a) do writeln(a[Where]);
450450 end;
451451```
452452
453453lazarus 0.9.11后将会完成参数:
454454
455455``` pascal
456456 procedure TForm1.FormPaint(Sender: TObject);
457457 begin
458458 with Canvas do begin
459459 Line(x1,y1,x2,y2);
460460 end;
461461 end;
462462```
463463
464-将光标放置在<strong>x1</strong>后,按<span class="kbd">Ctrl</span>+<span class="kbd">Shift</span>+<span class="kbd">C</span>将得到:
464+将光标放置在x1后,按`Ctrl`+`Shift`+`C`将得到:
465465
466466``` pascal
467467 procedure TForm1.FormPaint(Sender: TObject);
468468 var
469469 x1: integer;
470470 begin
471471 with Canvas do begin
472472 Line(x1,y1,x2,y2);
473473 end;
474474 end;
475475```
476476
477477### 过程调用自动完成
478478
479479代码完成可以通过调用语句本身创建一个新程序。假设你刚编写声明
480480
481481`DoSomething(Width);`
482482
483483``` pascal
484484procedure SomeProcedure;
485485var
486486 Width: integer;
487487begin
488488 Width:=3;
489489 DoSomething(Width);
490490end;
491491```
492492
493-将光标放在标识符<strong>DoSomething</strong>上,按<span class="kbd">Ctrl</span>+<span class="kbd">Shift</span>+<span class="kbd">C</span>,将得到:
493+将光标放在标识符DoSomething上,按`Ctrl`+`Shift`+`C`,将得到:
494494
495495``` pascal
496496procedure DoSomething(aWidth: LongInt);
497497begin
498498
499499end;
500500
501501procedure SomeProcedure;
502502var
503503 Width: integer;
504504begin
505505 Width:=3;
506506 DoSomething(Width);
507507end;
508508```
509509
510510它不会创建函数或方法。
511511
512512### 反转类自动完成
513513
514514声明当前私有方法。自Lazarus 0.9.21后可用。
515515
516516如:
517517
518518` procedure TForm1.DoSomething(Sender: TObject);`\
519519` begin`\
520520` end;`
521521
522-DoSomething未被声明,按<span class="kbd">Ctrl</span>+<span class="kbd">Shift</span>+<span class="kbd">C</span>,将添加TForm1类的私有方法
522+DoSomething未被声明,按`Ctrl`+`Shift`+`C`,将添加TForm1类的私有方法
523523
524524`procedure DoSomething(Sender: TObject);`
525525
526526对于 Delphians:
527527
528528Lazarus下完成工作始终是:从类接口来实现向后/反转类声明。Delphi是两个方向,但它有个缺点:让你不注意的一个错字会很容易的创建一个方法。
529529
530530### 注释和代码自动完成
531531
532532Code completion tries to keep comments where they belong. For example:
533533
534534` FList: TList; // list of TComponent`\
535535` FInt: integer;`
536536
537537When inserting a new variable between FList and FInt, the comment is kept in the FList line. Same is true for
538538
539539` FList: TList; { list of TComponent`\
540540`   This is a comment over several lines, starting`\
541541`   in the FList line, so codetools assumes it belongs `\
542542`   to the FLIst line and will not break this `\
543543`   relationship. Code is inserted behind the comment. }`\
544544` FInt: integer;`
545545
546546If the comment starts in the next line, then it will be treated as if it belongs to the code below. For example:
547547
548548` FList: TList; // list of TComponent`\
549549`   { This comment belongs to the statement below. `\
550550`     New code is inserted above this comment and `\
551551`     behind the comment of the FList line. }`\
552552` FInt: integer;`
553553
554554### 方法更新
555555
556-通常类完成将添加缺少的方法体,自0.9.27,如果类中的方法不同,那么方法体将被更新,如你有一个<strong>DoSomething</strong>方法:
556+通常类完成将添加缺少的方法体,自0.9.27,如果类中的方法不同,那么方法体将被更新,如你有一个DoSomething方法:
557557
558558``` pascal
559559public
560560 procedure DoSomething;
561561end;
562562
563563procedure TForm.DoSomething;
564564begin
565565end;
566566```
567567
568568添加一个参数:
569569
570570``` pascal
571571 public
572572 procedure DoSomething(i: integer);
573573 end;
574574```
575575
576-按<span class="kbd">Ctrl</span>+<span class="kbd">Shift</span>+<span class="kbd">C</span>,该方法声明将被更新,新的参数将被更新:
576+按`Ctrl`+`Shift`+`C`,该方法声明将被更新,新的参数将被更新:
577577
578578``` pascal
579579procedure TForm.DoSomething(i: integer);
580580begin
581581end;
582582```
583583
584584## 重构
585585
586586### 互换指派
587587
588588"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语句互换。~~
589589
590590如:\
591591procedure DoSomething;
592592
593593`begin`\
594594`  AValueStudio:= BValueStudio;`\
595595`  AValueAppartment :=BValueAppartment;`\
596596`  AValueHouse:=BValueHouse;`\
597597`end;`
598598
599599选择要反转的代码,右击选择重构-\>互换指派”。(或者,Source菜单-\>重构-\>互换指派)。
600600
601601结果:
602602
603603`procedure DoSomething;`\
604604`begin`\
605605`  BValueStudio     := AValueStudio;`\
606606`  BValueAppartment := AValueAppartment;`\
607607`  BValueHouse      := AValueHouse;`\
608608`end;`
609609
610610### 封装所选
611611
612-选择一些内容,按<span class="kbd">Ctrl</span>+<span class="kbd">Shift</span>+<span class="kbd">N</span>,会弹出一个对话框,你可以选择一项,之后,会将所选择的内容,括住。
612+选择一些内容,按`Ctrl`+`Shift`+`N`,会弹出一个对话框,你可以选择一项,之后,会将所选择的内容,括住。
613613
614614如,你选择了try..finally项,那么,你选择的内容将会被try..finally括住。
615615
616616你可以在选择内容上右击,源代码-\>封装所选;或者,Source菜单-\>封装所选,都可以实现此功能。
617617
618618### 重命名标识符
619619
620-将光标放在标识符上,并调用它(按<span class="kbd">F2</span>,或右击重构-\>重命名标识符;也可以在Source菜单-\>重构-\>重命名标识符)。
620+将光标放在标识符上,并调用它(按`F2`,或右击重构-\>重命名标识符;也可以在Source菜单-\>重构-\>重命名标识符)。
621621
622622将弹出对话框,输入新的标识符名称,设置搜索范围。
623623
624624- It will rename all occurences and only those that actually use this declaration. That means it does not rename declarations with the same name.
625625- ~~它将重命名所有出现,只有那些真正使用这个声明。这意味着它不重命名声明名称相同的。~~
626626- And it will first check for name conflicts.
627627- ~~它将首先检查名称冲突。~~
628628- Limits: It only works on pascal sources, does not yet rename files nor adapt lfm/lrs files nor lazdoc files.
629629- ~~限制:它仅适用于Pascal源文件,还没有重命名的文件,不适用LFM/LRS文件,也不适用,lazdoc文件。~~
630630
631631### 查找标识符参考
632632
633-将光标放在标识符上,并调用它(按<span class="kbd">Ctrl</span>+<span class="kbd">Shift</span>+<span class="kbd">I</span>,或右击查找-\>查找标识符参考;也可以在查找菜单-\>查找标识符参考);
633+将光标放在标识符上,并调用它(按`Ctrl`+`Shift`+`I`,或右击查找-\>查找标识符参考;也可以在查找菜单-\>查找标识符参考);
634634
635635在出现的对话框中设置搜索范围,IDE将搜索所有出现的,只有那些真正使用这一标识符的,意味着不会显示相同名称的。
636636
637637### 显示抽象方法
638638
639639This 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.
640640
641641### 抽取过程
642642
643643查看 [[IDE Window: Extract Procedure/zh CN|抽取过程]]
644644
645645## 查找声明
646646
647647将光标定位在要查找声明的标识符上,右击选择查找声明。之后,将搜索并跳转到所选择标识符的定义部分。
648648
649649Every find declaration sets a Jump Point. That means you jump with find declaration to the declaration and easily jump back with Search -\> Jump back.
650650
651651在Delphi上有些不同:
652652
653653The 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:
654654
655655The *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.
656656
657657~~*可见*属性是在TControl (controls.pp)中定义的,然后重新定义TCustomForm在TForm。查找声明时,首先找到TForm,之后再查找时会跳转找到TControl。~~
658658
659659像TColor类型,对于编译器它是一个简单的'longint'类型,但在源中其定义是:
660660
661661`TGraphicsColor = -$7FFFFFFF-1..$7FFFFFFF;`\
662662`TColor = TGraphicsColor;`
663663
664664和*前向定义类*类似,如TControl中,有一个私有变量
665665
666666`FHostDockSite: TWinControl;`
667667
668668查找声明TWinControl,将跳到前向定义。
669669
670670`TWinControl = class;`
671671
672672之后再跳转到真正实现部分
673673
674674`TWinControl = class(TControl)`
675675
676676这样你就可以跟踪每个标识符或查找负载。
677677
678678**提示:**
679679
680-- 按 <span class="kbd">Ctrl</span>+<span class="kbd">H</span> 跳回来
680+- 按 `Ctrl`+`H` 跳回来
681681- 查看所有跳转历史:查看菜单-\>查看跳转历史
682682- With a 5 button Mouse you can use the 2 extra buttons to go forward/backward between the visited points
683683- ~~用5键鼠标,可以使用2个额外的按钮来实现前进/后退光标位置~~
684684
685685
686686(你可以使用[[IDE Window: EditorMouseOptionsAdvanced|高级鼠标选项]]来映射)
687687
688688## 标识符自动完成
689689
690-按<span class="kbd">Ctrl</span>+<span class="kbd">space</span>调用标识符自动完成,它将显示范围内的所有标识符提示。如:
690+按`Ctrl`+`space`调用标识符自动完成,它将显示范围内的所有标识符提示。如:
691691
692692` procedure TForm1.FormCreate(Sender: TObject);`\
693693` begin`\
694694`   |`\
695695` end;`
696696
697-在<strong>begin</strong>和<strong>end</strong>间按<span class="kbd">Ctrl</span>+<span class="kbd">space</span>,IDE将分析你的代码,显示所有标识符列表。结果会被缓存,第二次调用时会很快。
697+在begin和end间按`Ctrl`+`space`,IDE将分析你的代码,显示所有标识符列表。结果会被缓存,第二次调用时会很快。
698698
699699**Delphians注意:**:Delphi称为代码完成。
700700
701701像这些标识符'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.
702702
703-标识符自动完成,并没有完成所有关键字。所以,人不能用它来完成repe到repeat。对于这些你可以按<span class="kbd">Ctrl</span>+<span class="kbd">W</span>[[Lazarus IDE Tools/zh CN|关键字自动完成]] 或 <span class="kbd">Ctrl</span>+<span class="kbd">J</span> [[Lazarus IDE Tools/zh CN|代码模板]]。
703+标识符自动完成,并没有完成所有关键字。所以,人不能用它来完成repe到repeat。对于这些你可以按`Ctrl`+`W`[[Lazarus IDE Tools/zh CN|关键字自动完成]] 或 `Ctrl`+`J` [[Lazarus IDE Tools/zh CN|代码模板]]。
704704
705705自0.9.27后,标识符自动完成了,完成了些关键字。
706706
707707Identifier completion shows even those identifiers, that are not compatible.
708708
709709### 前缀
710710
711711你可以使用一个单词或字母做为前缀,比如说:
712712
713713` procedure TForm1.FormCreate(Sender: TObject);`\
714714` begin`\
715715`   Ca|ption`\
716716` end;`
717717
718-在<strong>Ca</strong>后使用标识符自动完成,将显示所有<strong>ca</strong>开头的标识符列表。
718+在Ca后使用标识符自动完成,将显示所有ca开头的标识符列表。
719719
720720### 键
721721
722722- 字母或数字:字符添加到源代码编辑器作为前缀,这将更新列表。
723723- 退格键:从前缀中删除一个字符,这将更新列表。
724724- Return: replace the whole word at cursor with the selected identifier and close the popup window.
725725- Shift+Return: as *Return*, but replaces only the prefix (left part) of the word at the cursor.
726726- 上/下键: 移动选择。
727727- ESC键: 不保存信息,关闭弹出对话框。
728728- 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'.
729729- Else: as *Return* and add the character to the source editor
730730
731731### 方法
732732
733-当光标在类中定义方法时,使用标识符自动完成会添加相应参数并添加<strong>override</strong>关键字。例如:
733+当光标在类中定义方法时,使用标识符自动完成会添加相应参数并添加override关键字。例如:
734734
735735``` pascal
736736TMainForm = class(TForm)
737737protected
738738 mous|
739739end;
740740```
741741
742742完成的**MouseDown**:
743743
744744``` pascal
745745TMainForm = class(TForm)
746746protected
747747 procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X,
748748 Y: Integer); override;
749749end;
750750```
751751
752752### 属性
753753
754754``` pascal
755755property MyInt: integer read |;
756756```
757757
758758标识符自动完成,将显示**FMyInt**和**GetMyInt**。
759759
760760``` pascal
761761property MyInt: integer write |;
762762```
763763
764764标识符自动完成,将显示**FMyInt**和**SetMyInt**。
765765
766766### 引用部分/单元名称
767767
768768In 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**).
769769
770770~~引用某些单元文件时,使用标识符自动完成,将显示它们的文件路径,文件名通常是小写的(像**avl_tree**),完成后,会插入像**AVL_Tree**一样的名称。~~
771771
772772### 语句
773773
774774``` pascal
775775procedure TMainForm.Button1Click(Sender: TObject);
776776begin
777777 ModalRe|;
778778end;
779779```
780780
781781变为:
782782
783783``` pascal
784784procedure TMainForm.Button1Click(Sender: TObject);
785785begin
786786 ModalResult:=|;
787787end;
788788```
789789
790790## 关键字自动完成
791791
792-按<span class="kbd">Ctrl</span>+<span class="kbd">W</span>键调用关键词自动完成。它显示了当前打开文件中的匹配到的关键词,你也可以在非Pascal源文件中使用,在注释中也可以使用。
792+按`Ctrl`+`W`键调用关键词自动完成。它显示了当前打开文件中的匹配到的关键词,你也可以在非Pascal源文件中使用,在注释中也可以使用。
793793
794794否则,它的工作方式等同于标识符自动完成。
795795
796796## Goto Include Directive
797797
798798"Goto Include Directive" in the search menu of the IDE jumps to {\$I filename} statement where the current include file is used.
799799
800800## 发布工程
801801
802802创建项目副本。If you want to send someone just the sources and compiler settings of your code, this function is your friend.
803803
804804一个项目目录包含了大量信息,很多是不需要再作公布:lpi文件包含了会话信息(像光标位置 、单元书签),项目目录包含了ppu、o及可执行文件。
805805
806806要发布工程,在工程菜单下使用发布工程。
807807
808808**注**:0.9.13版本后,有了新的解决方法,它将会话信息存储在了以lps为扩展名的文件里,这样,当你发布时,lpi文件会清爽很多。
809809
810810在对话框中你可以设置排除列表和过滤器,也可以完成后使用命令压缩成一个档案。
811811
812812## 注释提示
813813
814814在某些地方IDE将显示帮助提示。如,将鼠标移动在一个标识符上等待几秒钟,将显示与此标识符相关的提示信息。
815815
816816IDE为了支持常见的注释、编程风格,通常会给予试探:
817817
818818### 显示注释提示
819819
820820注释声明中以**\<**开头(没有空行),将作为其上的提示:
821821
822822``` pascal
823823var
824824 {Comment}
825825 Identifier: integer;
826826```
827827
828828注释在**\<**之后。
829829
830830与标识符同行的注释:
831831
832832``` pascal
833833var
834834 identifier, // Comment
835835 other,
836836```
837837
838838注释和定义在同一行:
839839
840840``` pascal
841841var
842842 identifier:
843843 char; // Comment
844844```
845845
846846**\<**示例:
847847
848848``` pascal
849849const
850850 a = 1;
851851 //< comment for a
852852 b = 2;
853853 // comment for c
854854 c = 3;
855855```
856856
857857支持三种注释方式
858858
859859``` pascal
860860 {Comment}(*Comment*)//Comment
861861 c = 1;
862862```
863863
864864注释中**\$**和**%**将被忽略。
865865
866866### 不显示注释信息
867867
868868用空行分隔的注释,将不会用于提示显示。像下面的类头部注释将不会被显示:
869869
870870``` pascal
871871type
872872 { TMyClass }
873873
874874 TMyClass = class
875875```
876876
877877类头部注释创建于类完成时。你可以关闭这个功能:在工具菜单-\>选项中,代码工具-\>Class completion-\>类的头注释。 如果你想显示这些提示,删除空行即可。
878878
879879下面的注释,GL_TRUE将会显示提示,GL_FALSE不会:
880880
881881``` pascal
882882 // Boolean
883883 GL_TRUE = 1;
884884 GL_FALSE = 0;
885885```
886886
887887---
888888*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