Difference between revisions of "Lazarus IDE Tools/zh CN"

From Lazarus wiki
m (引入文件)
m (Fixed syntax highlighting; deleted category included in page template)
 
(36 intermediate revisions by one other user not shown)
Line 11: Line 11:
 
{|
 
{|
 
|-
 
|-
| [[Lazarus_IDE_Tools#Find Declaration|声明跳转]] || {{keypress|Ctrl}}+点击 or {{keypress|Alt}}+{{keypress|Up}} (跳转到声明的类型或变量)
+
| [[Lazarus_IDE_Tools/zh_CN#查找声明|查找声明]] || {{keypress|Ctrl}}+点击 or {{keypress|Alt}}+{{keypress|Up}} (跳转到声明的类型或变量)
 
|-
 
|-
| [[Lazarus_IDE_Tools#Method Jumping|方法跳转]] || {{keypress|Ctrl}}+{{keypress|Shift}}+{{keypress|Up}} (在定义部分和实现部分进行切换。看见一个定义,就可以用快键方式,直接找到它的实现部分。)
+
| [[Lazarus_IDE_Tools/zh_CN#方法跳转|方法跳转]] || {{keypress|Ctrl}}+{{keypress|Shift}}+{{keypress|Up}} (在定义部分和实现部分进行切换。看见一个定义,就可以用快键方式,直接找到它的实现部分。)
 
|-
 
|-
| [[Lazarus_IDE_Tools#Code Templates|代码模板]] || {{keypress|Ctrl}}+{{keypress|J}}
+
| [[Lazarus_IDE_Tools/zh_CN#代码模板|代码模板]] || {{keypress|Ctrl}}+{{keypress|J}}
 
|-
 
|-
| [[Lazarus_IDE_Tools#Syncro Edit|Syncro 编辑(同步编辑)]] || {{keypress|Ctrl}}+{{keypress|J}} (需要选择文本)
+
| [[Lazarus_IDE_Tools/zh_CN#Syncro 编辑(同步编辑)|Syncro 编辑(同步编辑)]] || {{keypress|Ctrl}}+{{keypress|J}} (需要选择文本)
 
|-
 
|-
| [[Lazarus_IDE_Tools#Code Completion|类提示]] || {{keypress|Ctrl}}+{{keypress|Shift}}+{{keypress|C}}
+
| [[Lazarus_IDE_Tools/zh_CN#类自动完成|类自动完成]] || {{keypress|Ctrl}}+{{keypress|Shift}}+{{keypress|C}}
 
|-
 
|-
| [[Lazarus_IDE_Tools#Identifier Completion|标识符提示]] || {{keypress|Ctrl}}+{{keypress|空格}}
+
| [[Lazarus_IDE_Tools/zh_CN#标识符自动完成|标识符自动完成]] || {{keypress|Ctrl}}+{{keypress|空格}}
 
|-
 
|-
| [[Lazarus_IDE_Tools#Word Completion|关键字提示]] || {{keypress|Ctrl}}+{{keypress|W}}
+
| [[Lazarus_IDE_Tools/zh_CN#关键字自动完成|关键字自动完成]] || {{keypress|Ctrl}}+{{keypress|W}}
 
|-
 
|-
| [[Lazarus_IDE_Tools#Parameter Hints|参数提示]] || {{keypress|Ctrl}}+{{keypress|Shift}}+{{keypress|空格}}
+
| [[Lazarus_IDE_Tools/zh_CN#参数提示|参数提示]] || {{keypress|Ctrl}}+{{keypress|Shift}}+{{keypress|空格}}
 
|-
 
|-
| [[Lazarus_IDE_Tools#Incremental Search|渐进式搜索]] || {{keypress|Ctrl}}+{{keypress|E}}
+
| [[Lazarus_IDE_Tools/zh_CN#渐进式搜索|渐进式搜索]] || {{keypress|Ctrl}}+{{keypress|E}}
 
|}
 
|}
  
Line 96: Line 96:
 
Jumping 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. ;)
 
Jumping 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. ;)
  
==Code Templates==
+
==代码模板==
Code Templates converts an identifier into a text or code fragment.
+
代码模板将标识符转换为文本或代码片段。
  
Code Templates default short cut is {{keypress|Ctrl}}+{{keypress|J}}. You can type an identifier, press {{keypress|Ctrl}}+{{keypress|J}} and the identifier is replaced by the text defined for the identifier. Code Templates can be defined in Environment -> Editor Options -> CodeTools.
+
默认快捷键是{{keypress|Ctrl}}+{{keypress|J}}。输入一个标识符,之后按{{keypress|Ctrl}}+{{keypress|J}}键将会替换该标识符为选定的内容。代码模板可以在“工具”菜单->“选项“->“代码工具”里设置。
 +
 
 +
如,在标识符<strong>classf</strong>后按{{keypress|Ctrl}}+{{keypress|J}},<strong>classf</strong>将被替换为:
  
Example:
 
Write the identifier 'classf', leave the cursor right behind the 'f' and press {{keypress|Ctrl}}+{{keypress|J}}. The 'classf' will be replaced by
 
 
  T = class(T)
 
  T = class(T)
 
  private
 
  private
Line 110: Line 110:
 
   destructor Destroy; override;
 
   destructor Destroy; override;
 
  end;
 
  end;
and the cursor is behind the 'T'.
 
You can get the list of templates by positioning the cursor on space (not on an identifier) and pressing {{keypress|Ctrl}}+{{keypress|J}}. The list of code templates will pop up. Use the cursor keys or type some chars to choose one. Return creates the selected template and Escape closes the pop up.
 
  
The biggest time savers are templates 'b'+{{keypress|Ctrl}}+{{keypress|J}} for begin..end.
+
并且光标在<strong>T</strong>后面。你可以将光标定位在空白位置(而不是标识符那里),按下 {{keypress|Ctrl}}+{{keypress|J}}键,将显示代码模板列表。选择一个,将返回选择的代码模板。
 +
 
 +
输入<strong>b</strong>之后,按{{keypress|Ctrl}}+{{keypress|J}}键,将显示 <strong>begin..end;</strong> 块。
 +
 
 +
==参数提示==
  
==Parameter Hints==
+
显示参数提示。
  
Parameter Hints shows a hint box with the parameter declarations for the current parameter list.
+
例如:
  
For example
+
Canvas.FillRect();
  
  Canvas.FillRect(|);
+
将光标置于括号中,按{{keypress|Ctrl}}+{{keypress|Shift}}+{{keypress|space}}键,将显示FillRect的参数提示信息。
  
Place the cursor in the brackets and press {{keypress|Ctrl}}+{{keypress|Shift}}+{{keypress|space}}. A hint box will show up showing the parameters of FillRect.
+
==渐进式搜索==
  
==Incremental Search==
+
渐进式搜索,按{{keypress|Ctrl}}+{{keypress|E}},输入搜索的文本,编辑器会高亮所有搜索到的。
  
Incremental Search changes the statusbar of the source editor. Type some characters and the editor will search and highlight immediately all occurrences in the text. Shortcut is {{keypress|Ctrl}}+{{keypress|e}}.
+
*例如,输入{{keypress|e}},将搜索并高亮显示所有<strong>e</strong>的匹配项。
*For example pressing {{keypress|e}} will search and highlight all occurrences of 'e'.
+
*然后,输入{{keypress|t}} ,将突出显示所有匹配<strong>et</strong>的文本。
*Then pressing {{keypress|t}} will search and highlight all occurrences of 'et' and so forth.
+
*跳转到下一个匹配项,按 {{keypress|F3}}({{keypress|Ctrl}}+{{keypress|E}});跳转到上一匹配项,按{{keypress|Shift}}+{{keypress|F3}}
*You can jump to the next with {{keypress|F3}} (or {{keypress|Ctrl}}+{{keypress|e}} while in search) and the previous with {{keypress|Shift}}+{{keypress|F3}}.
+
*{{keypress|Backspace}} 删除最后一个字符。
*Backspace deletes the last character
+
*停止搜索,可以按{{keypress|Enter}}键,或者在代码编辑器中点击鼠标。
*return stops the search without adding a new line in the editor.
 
 
*You can resume the last search by pressing {{keypress|Ctrl}}+{{keypress|e}} a second time, immediately after you started incr-search with {{keypress|Ctrl}}+{{keypress|e}}. that is while the search term is still empty.
 
*You can resume the last search by pressing {{keypress|Ctrl}}+{{keypress|e}} a second time, immediately after you started incr-search with {{keypress|Ctrl}}+{{keypress|e}}. that is while the search term is still empty.
*Paste {{keypress|Ctrl}}+{{keypress|V}} will append the text from the clipboard to the current search text (since lazarus 0.9.27 r19824).
+
*{{keypress|Ctrl}}+{{keypress|V}}键,粘贴剪贴板中的内容到当前搜索(因为lazarus 0.9.27 r19824)。
 +
 
 +
===注意:快速搜索与渐进式搜索的标识符===
  
===Hint: Quick searching an identifier with incremental search===
+
*Place text cursor on identifier (do not select anything) <strike>将光标放在标识符处(不要选择任何内容)。</strike>
 +
*按{{keypress|Ctrl}}+{{keypress|C}}键,将复制选择的标识符到剪贴板。
 +
*按{{keypress|Ctrl}}+{{keypress|E}}键,开始渐进式搜索。
 +
*按{{keypress|Ctrl}}+{{keypress|V}}键,搜索标识符(自0.9.27)。
 +
*{{keypress|F3}},向下搜索,{{keypress|Shift}}+{{keypress|F3}}向下搜索。
 +
*使用任意键(如,光标左、右键)来终止搜索。
  
*Place text cursor on identifier (do not select anything)
+
==Syncro 编辑(同步编辑)==
*Press {{keypress|Ctrl}}+{{keypress|C}}. The source editor will select the identifier and copy it to the clipboard
 
*Press {{keypress|Ctrl}}+{{keypress|E}} to start incremental search
 
*Press {{keypress|Ctrl}}+{{keypress|V}} to search for the identifier (since 0.9.27)
 
*Use {{keypress|F3}} and {{keypress|Shift}}+{{keypress|F3}} to quickly jump to next/previous.
 
*Use any key (for example cursor left or right) to end the search
 
  
==Syncro Edit==
+
Syncro Edit(同步编辑)可以让你在同一时间同步编辑所有匹配到的内容。你简单的在一个地方编辑,所有匹配的内容也会同步更新。
  
Syncro Edit allows you to edit all occurrences of a word at the same time (synchronized). You simple edit the word in one place, and as you type, all other occurrences of the word are updated too.
 
  
Syncro Edit works on all words in a selected area:
+
它适用于所有选择区域的文本:
* Select a block of text
+
* 选择文本块。
* press {{keypress|Ctrl}}+{{keypress|J}} or click the icon in the gutter. (This only work, if there are any words that occur more than once in the selection.
+
* {{keypress|Ctrl}}+{{keypress|J}}或,点击编辑左侧显示的“编辑图标”([[File:SyncroEditIcon.png]])。按{{keypress|tab}}键,选择要编辑的内容。
* use the {{keypress|tab}} key to select the word you want to edit (if several different words occurred more than once)
+
* 输入新内容。
* Edit the word
+
* {{keypress|Esc}}键完成编辑。
* Press {{keypress|Esc}} to finish
 
  
See an animated example [[New_IDE_features_since#Syncron-Edit|here]]
+
这里有[[New_IDE_features_since#Syncron-Edit|动画演示]]
  
* Note: {{keypress|Ctrl}}+{{keypress|J}} is also used for template edit. It switches it's meaning if you select some text.
+
{{Note| {{keypress|Ctrl}}+{{keypress|J}}也是代码模板的快捷键,如果你选择的不是文本块的话。}}
  
==Find next / previous word occurrence==
+
==查找下一个/上一个出现的单词==
  
The two functions can be found in the popup menu of the source editor
+
这两个功能,可以在源代码编辑器的弹出菜单中找到:
  
*Source editor / popup menu / Find / Find next word occurrence
+
*源代码编辑器 / 弹出菜单 / 查找 / 查找下一个发现的词
*Source editor / popup menu / Find / Find previous word occurrence
+
*源代码编辑器 / 弹出菜单 / 查找 / 查找前一个发现的词
  
And you can assign them shortcuts in the editor options.
+
And you can assign them shortcuts in the editor options.<strike>你也可以在查找菜单中,找到相应菜单项,它与其功能相同,当然也可以使用快捷键。</strike>
  
==Code Completion==
+
==代码自动完成==
Code Completion can be found in the IDE menu Edit -> Complete Code and has as standard short cut {{keypress|Ctrl|Shift|C}}.
 
  
For Delphians:
+
代码自动完成,可以在“编辑”菜单->“自动完成代码”,或按{{keypress|Ctrl|Shift|C}}键。(新版的Lazarus,在“Source”菜单->“自动完成代码”)
Delphi calls "code completion" the function showing the list of identifiers at the current source position ({{keypress|Ctrl|Space}}). Under Lazarus this is called "Identifier completion".
 
  
Code Completion combines several powerful functions. Examples:
+
对于Delphians:
* Class Completion: completes properties, adds/updates method bodies, add private variables and private access methods
 
* Forward Procedure Completion: adds procedure bodies
 
* Event Assignment Completion: completes event assignments and adds method definition and body
 
* Variable Declaration Completion: adds local variable definitions
 
* Procedure Call Completion: adds a new procedure
 
* Reversed procedure completion: adds procedure declarations for procedure/function bodies
 
* Reversed class completion: adds method declarations for method bodies
 
  
Which function is used, depends on the cursor position in the editor and will be explained below.
+
Delphi的“代码完成”,按{{keypress|Ctrl|Space}}将显示标识符列表。在Lazarus中称为“标识符提示”。
  
Code Completion can be found in the IDE menu Edit -> Complete Code and has as standard short cut {{keypress|Ctrl|Shift|C}}.
+
代码自动完成,有多种强大功能:
 +
* 类完成:自动完成属性,在方法体中增加/更新私有变量或私有方法。
 +
* [[Forward_Referencing/zh_CN|前向引用]]过程完成: 添加过程体。
 +
* 事件赋值完成:完成事件赋值,并增加了方法定义和主体。
 +
* 变量声明完成:增加了局部变量定义。
 +
* 过程调用完成:添加新过程。
 +
* 反转过程完成:添加过程/函数体声明。
 +
* 反转类完成:添加了方法体声明。
  
===Class Completion===
+
这个功能的使用,取决于编辑器中光标的位置,下面进行说明。
  
The most powerful code completion feature is "Class Completion". You write a class, add the methods and properties and Code Completion will add the method bodies, the property access methods/variables and the private variables.
+
===类自动完成===
  
For example: Create a class (see Code Templates to save you some type work):
+
<strong>(翻译不完善不完整,需要修订)</strong>
 +
 
 +
“类完成”是代码完成中最强大的,编写一个类,添加方法和属性,代码完成,将添加方法休,属性访问方法和变量。
 +
 
 +
如,创建一个类(见代码模板,以节省你的工作时间):
  
 
  TExample = class(TObject)
 
  TExample = class(TObject)
Line 199: Line 202:
 
   destructor Destroy; override;
 
   destructor Destroy; override;
 
  end;
 
  end;
Position the cursor somewhere in the class and press {{keypress|Ctrl|Shift|C}}. This will create the method missing bodies and move the cursor to the first created method body, so you can just start writing the class code:
+
 
 +
在类中,按{{keypress|Ctrl|Shift|C}}键,将会创建缺少的方法,并将光标移到创建的第一个方法体中,所以,你可以开始编写类代码:
  
 
  { TExample }
 
  { TExample }
Line 212: Line 216:
 
   inherited Destroy;
 
   inherited Destroy;
 
  end;
 
  end;
Note: The '|' is the cursor and is not added.
+
留意: '|'是光标位置。
  
Hint: You can jump between a method and its body with {{keypress|Ctrl|Shift|Up}}.
+
提示:你可以按按{{keypress|Ctrl|Shift|Up}}键,在方法与方法体间跳转。
  
You can see, that the IDE added the 'inherited Destroy' call too. This is done, if there is an 'override' keyword in the class definition.
+
你可以看到,在IDE中加入了<strong>继承销毁</strong>,因为,在类中定义了<strong>override</strong>关键字。
  
Now add a method DoSomething:
+
现在,添加一个DoSomething方法:
  
 
  TExample = class(TObject)
 
  TExample = class(TObject)
Line 227: Line 231:
 
  end;
 
  end;
  
Then press {{keypress|Ctrl|Shift|C}} and the IDE will add
+
{{keypress|Ctrl|Shift|C}},将添加:
  
 
  procedure TExample.DoSomething(i: integer);
 
  procedure TExample.DoSomething(i: integer);
Line 233: Line 237:
 
   |
 
   |
 
  end;
 
  end;
You can see, that the new method body is inserted between Create and Destroy, exactly as in the class definition. This way the bodies keep the same logical ordering as you define. You can define the insertion policy in Environment > Codetools Options -> Code Creation.
 
  
'''Complete Properties'''<br>
+
你可以看到新的方法体中插入了创建和销毁,因为在类中已经定义。You can define the insertion policy in Environment > Codetools Options -> Code Creation.
Add a property AnInteger:
+
 
 +
'''完成属性'''
 +
添加一个AnInteger属性:
 
  TExample = class(TObject)
 
  TExample = class(TObject)
 
  public
 
  public
Line 244: Line 249:
 
   property AnInteger: Integer;
 
   property AnInteger: Integer;
 
  end;
 
  end;
Press Ctrl+Shift+C and you will get:
+
 
 +
按{{keypress|Ctrl|Shift|C}}将得到:
 
  procedure TExample.SetAnInteger(const AValue: integer);
 
  procedure TExample.SetAnInteger(const AValue: integer);
 
  begin
 
  begin
Line 250: Line 256:
 
   FAnInteger:=AValue;
 
   FAnInteger:=AValue;
 
  end;
 
  end;
The code completion has added a Write access modifier and added some common code.
+
 
Jump to the class with {{keypress|Ctrl|Shift|Up}} to see the new class:
+
代码完成增加了一个写访问修饰符,并增加了一些常代码,跳转到类,按{{keypress|Ctrl|Shift|Up}}
 
  TExample = class(TObject)
 
  TExample = class(TObject)
 
  private
 
  private
Line 262: Line 268:
 
   property AnInteger: integer read FAnInteger write SetAnInteger;
 
   property AnInteger: integer read FAnInteger write SetAnInteger;
 
  end;
 
  end;
The property was extended by a Read and Write access modifier. The class got the new section 'private' with a Variable 'FAnInteger' and the method 'SetAnInteger'.
+
 
 +
该属性继承了一个读取和写入访问修饰符,这个类得到了一个新的private(私有)变量FAnInteger和SetAnInteger方法。
 +
 
 
It 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.
 
It 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.
  
Creating a read only property:
+
创建一个只读属性:
 
  property PropName: PropType read;
 
  property PropName: PropType read;
Will be expanded to
+
 
 +
将它继承:
 
  property PropName: PropType read FPropName;
 
  property PropName: PropType read FPropName;
Creating a write only property:
+
 
 +
创建一个只写属性:
 
   property PropName: PropType write;
 
   property PropName: PropType write;
Will be expanded to
+
 
 +
将它继承:
 
  property PropName: PropType write SetPropName;
 
  property PropName: PropType write SetPropName;
Creating a read only property with a Read method:
+
 
 +
创建一个只读属性与读取方法:
 
  property PropName: PropType read GetPropName;
 
  property PropName: PropType read GetPropName;
Will be kept and a GetPropName function will be added:
+
 
 +
保持和GetPropName功能:
 
  function GetpropName: PropType;
 
  function GetpropName: PropType;
Creating a property with a stored modifier:
+
 
 +
创建一个属性与存储的修饰符:
 
  property PropName: PropType stored;
 
  property PropName: PropType stored;
Will be expanded to
+
 
 +
将它继承:
 
  property PropName: PropType read FPropName write SetPropName stored PropNameIsStored;
 
  property PropName: PropType read FPropName write SetPropName stored PropNameIsStored;
 +
 
Because stored is used for streaming read and write modifiers are automatically added as well.
 
Because stored is used for streaming read and write modifiers are automatically added as well.
  
Hint:
+
提示:
Identifier completion also recognizes incomplete properties and will suggest the default names. For example:
+
标识符完成允许不完整的属性,并且会提示的默认名称。例如:
 
  property PropName: PropType read |;
 
  property PropName: PropType read |;
Place the cursor one space behind the 'read' keyword and press Ctrl+Space for the identifier completion. It will present you the variable 'FPropName' and the procedure 'SetPropName'.
+
将光标置于一个空格的''的关键字,然后按{{keypress|Ctrl|Space}},它会给出变量'FPropName'和过程'SetPropName“。
  
===Forward Procedure Completion===
+
===前向引用自动完成===
"Forward Procedure Completion" is part of the Code Completion and adds missing procedure bodies. It is invoked, when the cursor is on a forward defined procedure.
+
前向引用自动完成是代码完成部分,用于添加缺少的过程体。当光标在一个前向定义的过程上时,
  
For example:
+
例如:
Add a new procedure to the interface section:
+
添加一个新过程在接口部分:
 
  procedure DoSomething;
 
  procedure DoSomething;
Place the cursor on it and press {{keypress|Ctrl|Shift|C}} for code completion. It will create in the implementation section:
+
将光标放在声明上,按{{keypress|Ctrl|Shift|C}},这将创建实现部分:
 
  procedure DoSomething;
 
  procedure DoSomething;
 
  begin
 
  begin
 
   |
 
   |
 
  end;
 
  end;
Hint: You can jump between a procedure definition and its body with {{keypress|Ctrl|Shift|Up}}.
+
提示:你可以按{{keypress|Ctrl|Shift|Up}},在过程定义与过程体间跳转。
  
The new procedure body will be added in front of the class methods. If there are already some procedures in the interface the IDE tries to keep the ordering. For example:
+
如果已经存在过程,新过程体将添加到类方法中,IDE试图保持有序,例如:
 
   procedure Proc1;
 
   procedure Proc1;
   procedure Proc2; // new proc
+
   procedure Proc2; // 新过程
 
   procedure Proc3;
 
   procedure Proc3;
If the bodies of Proc1 and Proc3 already exists, then the Proc2 body will be inserted between the bodies of Proc1 and Proc3. This behaviour can be setup in Environment > Codetools Options -> Code Creation.
 
  
Multiple procedures:
+
如果Proc1和Proc3已经存在,那么Proc2部分会在Proc1和Proc3间添加。This behaviour can be setup in Environment > Codetools Options -> Code Creation.
  procedure Proc1_Old; // body exists
+
 
  procedure Proc2_New; // body does not exists
+
多个过程:
 +
  procedure Proc1_Old; // 过程体存在
 +
  procedure Proc2_New; // 过程体不存在
 
  procedure Proc3_New; //  "
 
  procedure Proc3_New; //  "
 
  procedure Proc4_New; //  "
 
  procedure Proc4_New; //  "
  procedure Proc5_Old; // body exists
+
  procedure Proc5_Old; // 过程体存在
Code Completion will add all 3 procedure bodies (Proc2_New, Proc3_New, Proc4_New).
+
代码完成,将添加3个过程体:(Proc2_New, Proc3_New, Proc4_New)
  
Why calling it "Forward Procedure Completion"?
+
为什么称它是“前向引用自动完成”?
 +
 
 +
先了解下,[[Forward_Referencing/zh_CN|前向引用]]。
  
 
Because 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.
 
Because 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.
  
===Event Assignment Completion===
+
===事件赋值自动完成===
"Event Assignment Completion" is part of the Code Completion and completes a single Event:=| statement. It is invoked, when the cursor is behind an assignment to an event.
+
 
 +
事件赋值自动完成,是代码自动完成的一部分,在使用时,将光标放在要赋值事件的后面。
 +
 
 +
例如,在FormCreate中添加一行:
 +
OnPaint:=
  
For example:
 
In a method, say the FormCreate event, add a line 'OnPaint:=':
 
 
  procedure TForm1.Form1Create(Sender: TObject);
 
  procedure TForm1.Form1Create(Sender: TObject);
 
  begin
 
  begin
 
   OnPaint:=|
 
   OnPaint:=|
 
  end;
 
  end;
The '|' is the cursor and should not be typed.
+
 
Then press Ctrl+Shift+C for code completion. The statement will be completed to
+
注意:<strong>|</strong>是光标所在位置。
 +
 
 +
按{{keypress|Ctrl|Shift|C}}后,代码将会:
 +
 
 
  OnPaint:=@Form1Paint;
 
  OnPaint:=@Form1Paint;
A new method Form1Paint will be added to the TForm1 class. Then class completion is started and you get:
+
 
 +
Form1Paint方法,将被添加到TForm1类中,
 +
 
 
  procedure TForm1.Form1Paint(Sender: TObject);
 
  procedure TForm1.Form1Paint(Sender: TObject);
 
  begin
 
  begin
 
   |
 
   |
 
  end;
 
  end;
This works just like adding methods in the object inspector.
+
这就像在对象观察器中添加方法。
  
Note:<br>
+
注意:<br>
You must place the cursor behind the ':=' assignment operator. If you place the cursor on the identifier (e.g. OnPaint) code completion will invoke "Local Variable Completion", which fails, because OnPaint is already defined.
+
你必须把光标放在<strong>:=</strong>后,但如果你将光标放在标识符后,那么将调用代码自动完成。
  
Hint:<br>
+
提示:<br> 你可以自定义方法名,如:
You can define the new method name by yourself. For example:
 
 
   OnPaint:=@ThePaintMethod;
 
   OnPaint:=@ThePaintMethod;
  
===Variable Declaration Completion===
+
===变量声明自动完成===
"Variable Declaration Completion" is part of the Code Completion and adds a local variable definition for a Identifier:=Term; statement. It is invoked, when the cursor is on the identifier of an assignment or a parameter.
+
变量声明自动完成,将未声明的变量对它声明。
  
For example:
+
如一个局部变量定义:
<syntaxhighlight>
+
标识符:=值;
 +
将光标放置在标识符后面。
 +
 
 +
<syntaxhighlight lang=pascal>
 
procedure TForm1.Form1Create(Sender: TObject);
 
procedure TForm1.Form1Create(Sender: TObject);
 
begin
 
begin
Line 355: Line 383:
 
end;
 
end;
 
</syntaxhighlight>
 
</syntaxhighlight>
Place the cursor on the 'i' or just behind it. Then press {{keypress|Ctrl|Shift|C}} for code completion and you will get:
+
将光标位在<strong>i</strong>后,按{{keypress|Ctrl|Shift|C}}将得到:
<syntaxhighlight>
+
 
 +
<syntaxhighlight lang=pascal>
 
procedure TForm1.Form1Create(Sender: TObject);
 
procedure TForm1.Form1Create(Sender: TObject);
 
var
 
var
Line 364: Line 393:
 
end;
 
end;
 
</syntaxhighlight>
 
</syntaxhighlight>
The codetools first checks, if the identifier 'i' is already defined and if not it will add the declaration 'var i: integer;'. The type of the identifier is guessed from the term right to the assignment ':=' operator. Numbers like the 3 defaults to Integer.
+
如果标识符<strong>i</strong>已经被定义,并且没有添加声明
 +
var i: integer;
 +
标识符的类型,通过赋值运算来得到类型。像数字3默认为整型。
  
Another example:
+
另一个例子:
<syntaxhighlight>
+
<syntaxhighlight lang=pascal>
 
type
 
type
 
   TWhere = (Behind, Middle, InFront);
 
   TWhere = (Behind, Middle, InFront);
Line 378: Line 409:
 
   end;
 
   end;
 
</syntaxhighlight>
 
</syntaxhighlight>
Place the cursor on 'Where' and press {{keypress|Ctrl|Shift|C}} for code completion. You get:
+
将光标放置在<strong>where</strong>后,按{{keypress|Ctrl|Shift|C}}将得到:
<syntaxhighlight>
+
<syntaxhighlight lang=pascal>
 
   procedure TForm1.Form1Create(Sender: TObject);
 
   procedure TForm1.Form1Create(Sender: TObject);
 
   var
 
   var
Line 389: Line 420:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
Since 0.9.11 Lazarus also completes parameters. For example
+
lazarus 0.9.11后将会完成参数:
<syntaxhighlight>
+
<syntaxhighlight lang=pascal>
 
   procedure TForm1.FormPaint(Sender: TObject);
 
   procedure TForm1.FormPaint(Sender: TObject);
 
   begin
 
   begin
Line 398: Line 429:
 
   end;
 
   end;
 
</syntaxhighlight>
 
</syntaxhighlight>
Place the cursor on 'x1' and press {{keypress|Ctrl|Shift|C}} for code completion. You get:
+
 
<syntaxhighlight>
+
将光标放置在<strong>x1</strong>后,按{{keypress|Ctrl|Shift|C}}将得到:
 +
<syntaxhighlight lang=pascal>
 
   procedure TForm1.FormPaint(Sender: TObject);
 
   procedure TForm1.FormPaint(Sender: TObject);
 
   var
 
   var
Line 410: Line 442:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
===Procedure Call Completion===
+
===过程调用自动完成===
Code completion can create a new procedure from a call statement itself.
+
代码完成可以通过调用语句本身创建一个新程序。假设你刚编写声明
 +
DoSomething(Width);
  
Assume you just wrote the statement "DoSomething(Width);"
+
<syntaxhighlight lang=pascal>
<syntaxhighlight>
 
 
procedure SomeProcedure;
 
procedure SomeProcedure;
 
var
 
var
Line 424: Line 456:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
Position the cursor over the identifier "DoSomething" and press {{keypress|Ctrl|Shift|C}} to get:
+
将光标放在标识符<strong>DoSomething</strong>上,按{{keypress|Ctrl|Shift|C}},将得到:
  
<syntaxhighlight>
+
<syntaxhighlight lang=pascal>
 
procedure DoSomething(aWidth: LongInt);
 
procedure DoSomething(aWidth: LongInt);
 
begin
 
begin
Line 440: Line 472:
 
end;
 
end;
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
它不会创建函数或方法。
  
It does not yet create functions nor methods.
+
===反转类自动完成===
  
===Reversed Class Completion===
+
声明当前私有方法。自Lazarus 0.9.21后可用。
  
"Reversed Class Completion" is part of the '''Code Completion''' and adds a private method declaration for the current method body. It is invoked, when the cursor is in a method body, not yet defined in the class.
+
如:
This feature is available since Lazarus 0.9.21.
 
 
 
For example:
 
 
   procedure TForm1.DoSomething(Sender: TObject);
 
   procedure TForm1.DoSomething(Sender: TObject);
 
   begin
 
   begin
 
   end;
 
   end;
  
The method DoSomething is not yet declared in TForm1. Press {{keypress|Ctrl|Shift|C}} and the IDE will add "procedure DoSomething(Sender: TObject);" to the private methods of TForm1.
+
DoSomething未被声明,按{{keypress|Ctrl|Shift|C}},将添加TForm1类的私有方法
 +
procedure DoSomething(Sender: TObject);
 +
 
 +
对于 Delphians:
  
For Delphians:
+
Lazarus下完成工作始终是:从类接口来实现向后/反转类声明。Delphi是两个方向,但它有个缺点:让你不注意的一个错字会很容易的创建一个方法。
Class completion works under Lazarus always in one way: From class interface to implementation or backwards/reversed from class implementation to interface. Delphi always invokes both directions. The Delphi way has the disadvantage, that if a typo will easily create a new method stub without noticing.
 
  
===Comments and Code Completion===
+
===注释和代码自动完成===
 
Code completion tries to keep comments where they belong.  
 
Code completion tries to keep comments where they belong.  
 
For example:
 
For example:
Line 477: Line 509:
 
   FInt: integer;
 
   FInt: integer;
  
===Method update===
+
===方法更新===
Normally class completion will add all missing method bodies. (Since 0.9.27) But if exactly one method differ between class and bodies then the method body is updated. For example: You have a method ''DoSomething''.
+
通常类完成将添加缺少的方法体,自0.9.27,如果类中的方法不同,那么方法体将被更新,如你有一个<strong>DoSomething</strong>方法:
<syntaxhighlight>
+
<syntaxhighlight lang=pascal>
  public
+
public
 
     procedure DoSomething;
 
     procedure DoSomething;
  end;
+
end;
  
 
procedure TForm.DoSomething;
 
procedure TForm.DoSomething;
Line 489: Line 521:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
Now add a parameter:
+
添加一个参数:
  
<syntaxhighlight>
+
<syntaxhighlight lang=pascal>
 
   public
 
   public
 
     procedure DoSomething(i: integer);
 
     procedure DoSomething(i: integer);
Line 497: Line 529:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
and invoke Code Completion ({{keypress|Ctrl|Shift|C}}). The method body will be updated and the new parameter will be copied:
+
{{keypress|Ctrl|Shift|C}},该方法声明将被更新,新的参数将被更新:
  
<syntaxhighlight>
+
<syntaxhighlight lang=pascal>
 
procedure TForm.DoSomething(i: integer);
 
procedure TForm.DoSomething(i: integer);
 
begin
 
begin
Line 505: Line 537:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
==Refactoring==
+
==重构==
  
===Invert Assignments===
+
===互换指派===
  
;Abstract: : "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.
+
"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.
 +
<strike>摘要:互换指派,将某些选定的Pascal语句互换。</strike>
  
Example:<br>
+
:<br>
 
  procedure DoSomething;
 
  procedure DoSomething;
 
  begin
 
  begin
Line 518: Line 551:
 
   AValueHouse:=BValueHouse;
 
   AValueHouse:=BValueHouse;
 
  end;
 
  end;
Select the lines with assignments (between begin and end) and do Invert Assignments. All assignments will be inverted and identation will be add automatically. For example:
 
  
Result:
+
选择要反转的代码,右击选择重构->互换指派”。(或者,Source菜单->重构->互换指派)。
 +
 
 +
结果:
 
  procedure DoSomething;
 
  procedure DoSomething;
 
  begin
 
  begin
Line 527: Line 561:
 
   BValueHouse      := AValueHouse;
 
   BValueHouse      := AValueHouse;
 
  end;
 
  end;
===Enclose Selection===
+
===封装所选===
Select some text and invoke it. A dialog will popup where you can select if the selection should be enclosed into '''try..finally''' or many other common blocks.
+
选择一些内容,按{{keypress|Ctrl|Shift|N}},会弹出一个对话框,你可以选择一项,之后,会将所选择的内容,括住。
 +
 
 +
如,你选择了try..finally项,那么,你选择的内容将会被try..finally括住。
 +
 
 +
你可以在选择内容上右击,源代码->封装所选;或者,Source菜单->封装所选,都可以实现此功能。
 +
 
 +
===重命名标识符===
 +
将光标放在标识符上,并调用它(按{{keypress|F2}},或右击重构->重命名标识符;也可以在Source菜单->重构->重命名标识符)。
  
===Rename Identifier===
+
将弹出对话框,输入新的标识符名称,设置搜索范围。
Place the cursor on an identifier and invoke it. A dialog will appear, where you can setup the search scope and the new name.
 
 
* It will rename all occurences and only those that actually use this declaration. That means it does not rename declarations with the same name.  
 
* It will rename all occurences and only those that actually use this declaration. That means it does not rename declarations with the same name.  
 +
* <strike>它将重命名所有出现,只有那些真正使用这个声明。这意味着它不重命名声明名称相同的。</strike>
 
* And it will first check for name conflicts.  
 
* And it will first check for name conflicts.  
 +
* <strike>它将首先检查名称冲突。</strike>
 
* Limits: It only works on pascal sources, does not yet rename files nor adapt lfm/lrs files nor lazdoc files.
 
* Limits: It only works on pascal sources, does not yet rename files nor adapt lfm/lrs files nor lazdoc files.
 +
* <strike>限制:它仅适用于Pascal源文件,还没有重命名的文件,不适用LFM/LRS文件,也不适用,lazdoc文件。</strike>
 +
 +
===查找标识符参考===
 +
将光标放在标识符上,并调用它(按{{keypress|Ctrl|Shift|I}},或右击查找->查找标识符参考;也可以在查找菜单->查找标识符参考);
  
===Find Identifier References===
+
在出现的对话框中设置搜索范围,IDE将搜索所有出现的,只有那些真正使用这一标识符的,意味着不会显示相同名称的。
Place the cursor on an identifier and invoke it. A dialog will appear, where you can setup the search scope. The IDE will then search for all occurences and only those that actually use this declaration. That means it does not show other declarations with the same name.
 
  
===Show abstract methods===
+
===显示抽象方法===
 
This feature lists and auto completes virtual, abstracts methods that need to be implemented.
 
This 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.
 
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.
  
===Extract Procedure===
+
===抽取过程===
  
See [[IDE_Window:_Extract_Procedure|Extract Procedure]]
+
查看 [[IDE_Window:_Extract_Procedure/zh_CN|抽取过程]]
  
==Find Declaration==
+
==查找声明==
Position the cursor on an identifier and do 'Find Declaration'. Then it will search the declaration of this identifier, open the file and jump to it.
+
 
 +
将光标定位在要查找声明的标识符上,右击选择查找声明。之后,将搜索并跳转到所选择标识符的定义部分。
  
 
Every find declaration sets a Jump Point. That means you jump with find declaration to the declaration and easily jump back with Search -> Jump back.
 
Every find declaration sets a Jump Point. That means you jump with find declaration to the declaration and easily jump back with Search -> Jump back.
  
There are some differences to Delphi:
+
 
 +
在Delphi上有些不同:
 +
 
 
The 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:
 
The 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:
  
Line 558: Line 606:
 
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.
 
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.
  
Same is true for types like TColor.
+
<strike>''可见''属性是在TControl (controls.pp)中定义的,然后重新定义TCustomForm在TForm。查找声明时,首先找到TForm,之后再查找时会跳转找到TControl。</strike>
For the compiler it is simply a 'longint'. But in the sources it is defined as
+
 
 +
像TColor类型,对于编译器它是一个简单的'longint'类型,但在源中其定义是:
 
  TGraphicsColor = -$7FFFFFFF-1..$7FFFFFFF;
 
  TGraphicsColor = -$7FFFFFFF-1..$7FFFFFFF;
 
  TColor = TGraphicsColor;
 
  TColor = TGraphicsColor;
  
And the same for '''forward defined classes''':
+
''前向定义类''类似,如TControl中,有一个私有变量
For instance in TControl, there is a private variable
 
 
  FHostDockSite: TWinControl;
 
  FHostDockSite: TWinControl;
Find declaration on TWinControl jumps to the forward definition
+
 
 +
查找声明TWinControl,将跳到前向定义。
 
  TWinControl = class;
 
  TWinControl = class;
And invoking it again jumps to the real implementation
+
 
 +
之后再跳转到真正实现部分
 
  TWinControl = class(TControl)
 
  TWinControl = class(TControl)
This way you can track down every identifier and find every overload.
 
  
'''Hints:'''  
+
这样你就可以跟踪每个标识符或查找负载。
* You can jump back with {{keypress|Ctrl|H}}.
+
 
* You can view/navigate all visited locations via Menu: View -> "jump history"
+
'''提示:'''  
 +
* {{keypress|Ctrl|H}} 跳回来
 +
* 查看所有跳转历史:查看菜单->查看跳转历史
 
* With a 5 button Mouse you can use the 2 extra buttons to go forward/backward between the visited points
 
* With a 5 button Mouse you can use the 2 extra buttons to go forward/backward between the visited points
:(you can remap the buttons using [[IDE_Window:_EditorMouseOptionsAdvanced#Change_History_Jumps_for_3_button_Mouse_.28follow_back_the_.22Source_Link.22_trail.29|advanced mouse options]])
+
* <strike>用5键鼠标,可以使用2个额外的按钮来实现前进/后退光标位置</strike>
 +
:(你可以使用[[IDE_Window:_EditorMouseOptionsAdvanced#Change_History_Jumps_for_3_button_Mouse_.28follow_back_the_.22Source_Link.22_trail.29|高级鼠标选项]]来映射)
  
==Identifier Completion==
+
==标识符自动完成==
"Identifier Completion" is invoked by {{keypress|Ctrl|space}}. It shows all identifiers in scope. For example:
+
{{keypress|Ctrl|space}}调用标识符自动完成,它将显示范围内的所有标识符提示。如:
  
 
   procedure TForm1.FormCreate(Sender: TObject);
 
   procedure TForm1.FormCreate(Sender: TObject);
Line 586: Line 638:
 
   end;
 
   end;
  
Place the cursor between ''begin'' and ''end'' and press {{keypress|Ctrl|space}}. The IDE/CodeTools will now parse all reachable code and present you a list of all found identifiers. The CodeTools cache the results, so invoking it a second time will be much faster.
+
在<strong>begin</strong>和<strong>end</strong>间按{{keypress|Ctrl|space}},IDE将分析你的代码,显示所有标识符列表。结果会被缓存,第二次调用时会很快。
 +
 
 +
'''Delphians注意:''':Delphi称为代码完成。
  
'''Note for Delphians:''' Delphi calls it ''Code completion''.
+
像这些标识符'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.
  
Some identifiers like 'Write', 'ReadLn', 'Low', 'SetLength', 'Self', 'Result', 'Copy' are built into the compiler and are not defined anywhere in source. 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.
+
标识符自动完成,并没有完成所有关键字。所以,人不能用它来完成repe到repeat。对于这些你可以按{{keypress|Ctrl|W}}[[Lazarus_IDE_Tools/zh_CN#关键字自动完成|关键字自动完成]] 或 {{keypress|Ctrl|J}} [[Lazarus_IDE_Tools/zh_CN#代码模板|代码模板]]。
  
''Identifier completion'' does not complete all '''keywords'''. So you can not use it to complete 'repe' to 'repeat'. For these things use {{keypress|Ctrl|W}} [[#Word Completion|Word Completion]] or {{keypress|Ctrl|J}} [[#Code Templates|Code Templates]]. Since 0.9.27 ''identifier completion'' completes some keywords.
+
自0.9.27后,标识符自动完成了,完成了些关键字。
  
 
Identifier completion shows even those identifiers, that are not compatible.
 
Identifier completion shows even those identifiers, that are not compatible.
  
===Prefix===
+
===前缀===
You can start identifier completion in a word. Then the letters to the left will be taken as prefix. For example:
+
你可以使用一个单词或字母做为前缀,比如说:
  
 
   procedure TForm1.FormCreate(Sender: TObject);
 
   procedure TForm1.FormCreate(Sender: TObject);
Line 604: Line 659:
 
   end;
 
   end;
  
The box will show you only the identifiers beginning with 'Ca'.
+
在<strong>Ca</strong>后使用标识符自动完成,将显示所有<strong>ca</strong>开头的标识符列表。
  
===Keys===
+
======
  
* Letter or number: add the character to the source editor and the current prefix. This will update the list.
+
* 字母或数字:字符添加到源代码编辑器作为前缀,这将更新列表。
* Backspace: remove the last character from source editor and prefix. Updates the list.
+
* 退格键:从前缀中删除一个字符,这将更新列表。
 
* Return: replace the whole word at cursor with the selected identifier and close the popup window.
 
* Return: replace the whole word at cursor with the selected identifier and close the popup window.
 
* Shift+Return: as ''Return'', but replaces only the prefix (left part) of the word at the cursor.
 
* Shift+Return: as ''Return'', but replaces only the prefix (left part) of the word at the cursor.
* Up/Down: move selection
+
* /下键: 移动选择。
* Escape: close popup without change
+
* ESC键: 不保存信息,关闭弹出对话框。
 
* 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'.
 
* 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'.
 
* Else: as ''Return'' and add the character to the source editor
 
* Else: as ''Return'' and add the character to the source editor
  
===Methods===
+
===方法===
  
When cursor is in a class definition and you identifier complete a method defined in an ancestor class the parameters and the override keyword will be added automatically. For example:
+
当光标在类中定义方法时,使用标识符自动完成会添加相应参数并添加<strong>override</strong>关键字。例如:
  
<syntaxhighlight>
+
<syntaxhighlight lang=pascal>
 
TMainForm = class(TForm)
 
TMainForm = class(TForm)
 
protected
 
protected
 
   mous|
 
   mous|
 
end;
 
end;
</DELPHI>
+
</syntaxhighlight>
  
Completing '''MouseDown''' gives:
+
完成的'''MouseDown'''
  
<syntaxhighlight>
+
<syntaxhighlight lang=pascal>
 
TMainForm = class(TForm)
 
TMainForm = class(TForm)
 
protected
 
protected
Line 636: Line 691:
 
         Y: Integer); override;
 
         Y: Integer); override;
 
end;
 
end;
</DELPHI>
+
</syntaxhighlight>
  
===Properties===
+
===属性===
  
<syntaxhighlight>
+
<syntaxhighlight lang=pascal>
 
property MyInt: integer read |;
 
property MyInt: integer read |;
</DELPHI>
+
</syntaxhighlight>
  
Identifier completion will show '''FMyInt''' and '''GetMyInt'''.
+
标识符自动完成,将显示'''FMyInt''''''GetMyInt'''
  
<syntaxhighlight>
+
<syntaxhighlight lang=pascal>
 
property MyInt: integer write |;
 
property MyInt: integer write |;
</DELPHI>
+
</syntaxhighlight>
  
Identifier completion will show '''FMyInt''' and '''SetMyInt'''.
+
标识符自动完成,将显示'''FMyInt''''''SetMyInt'''
  
===Uses section / Unit names===
+
===引用部分/单元名称===
  
 
In 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''').
 
In 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''').
  
===Statements===
+
<strike>引用某些单元文件时,使用标识符自动完成,将显示它们的文件路径,文件名通常是小写的(像'''avl_tree'''),完成后,会插入像'''AVL_Tree'''一样的名称。</strike>
  
<DELPHI>
+
===语句===
 +
 
 +
<syntaxhighlight lang=pascal>
 
procedure TMainForm.Button1Click(Sender: TObject);
 
procedure TMainForm.Button1Click(Sender: TObject);
 
begin
 
begin
 
   ModalRe|;
 
   ModalRe|;
 
end;
 
end;
</DELPHI>
+
</syntaxhighlight>
  
becomes:
+
变为:
  
<DELPHI>
+
<syntaxhighlight lang=pascal>
 
procedure TMainForm.Button1Click(Sender: TObject);
 
procedure TMainForm.Button1Click(Sender: TObject);
 
begin
 
begin
 
   ModalResult:=|;
 
   ModalResult:=|;
 
end;
 
end;
</DELPHI>
+
</syntaxhighlight>
  
==Word Completion==
+
==关键字自动完成==
"Word Completion" is invoked by {{keypress|Ctrl|W}}. It shows all words of all currently open editors and can therefore be used in non pascal sources, in comments and for keywords.
+
{{keypress|Ctrl|W}}键调用关键词自动完成。它显示了当前打开文件中的匹配到的关键词,你也可以在非Pascal源文件中使用,在注释中也可以使用。
  
Otherwise it works the same as identifier completion.
+
否则,它的工作方式等同于标识符自动完成。
  
 
==Goto Include Directive==
 
==Goto Include Directive==
 
"Goto Include Directive" in the search menu of the IDE jumps to {$I filename} statement where the current include file is used.
 
"Goto Include Directive" in the search menu of the IDE jumps to {$I filename} statement where the current include file is used.
  
==Publish Project==
+
==发布工程==
Creates a copy of the whole project. If you want to send someone just the sources and compiler settings of your code, this function is your friend.
+
 
 +
创建项目副本。If you want to send someone just the sources and compiler settings of your code, this function is your friend.
 +
 
 +
一个项目目录包含了大量信息,很多是不需要再作公布:lpi文件包含了会话信息(像光标位置 、单元书签),项目目录包含了ppu、o及可执行文件。
 +
 
 +
要发布工程,在工程菜单下使用发布工程。
 +
 
 +
'''注''':0.9.13版本后,有了新的解决方法,它将会话信息存储在了以lps为扩展名的文件里,这样,当你发布时,lpi文件会清爽很多。
 +
 
 +
在对话框中你可以设置排除列表和过滤器,也可以完成后使用命令压缩成一个档案。
 +
 
 +
==注释提示==
 +
 
 +
在某些地方IDE将显示帮助提示。如,将鼠标移动在一个标识符上等待几秒钟,将显示与此标识符相关的提示信息。
 +
 
 +
IDE为了支持常见的注释、编程风格,通常会给予试探:
 +
 
 +
===显示注释提示===
 +
 
 +
注释声明中以'''<'''开头(没有空行),将作为其上的提示:
 +
 
 +
<syntaxhighlight lang=pascal>var
 +
  {Comment}
 +
  Identifier: integer;</syntaxhighlight>
 +
 
 +
注释在'''<'''之后。
 +
 
 +
与标识符同行的注释:
 +
 
 +
<syntaxhighlight lang=pascal>var
 +
  identifier, // Comment
 +
  other,</syntaxhighlight>
 +
 
 +
注释和定义在同一行:
 +
 
 +
<syntaxhighlight lang=pascal>var
 +
  identifier:
 +
    char; // Comment</syntaxhighlight>
 +
 
 +
'''<'''示例:
 +
 
 +
<syntaxhighlight lang=pascal>const
 +
  a = 1;
 +
  //< comment for a
 +
  b = 2;
 +
  // comment for c
 +
  c = 3;</syntaxhighlight>
 +
 
 +
支持三种注释方式
 +
<syntaxhighlight lang=pascal>  {Comment}(*Comment*)//Comment
 +
  c = 1;</syntaxhighlight>
 +
 
 +
注释中'''$'''和'''%'''将被忽略。
 +
 
 +
===不显示注释信息===
 +
 
 +
用空行分隔的注释,将不会用于提示显示。像下面的类头部注释将不会被显示:
 +
 
 +
<syntaxhighlight lang=pascal>type
 +
  { TMyClass }
 +
 
 +
  TMyClass = class</syntaxhighlight>
  
A normal project directory contains a lot of information. Most of it is not needed to be published:
+
类头部注释创建于类完成时。你可以关闭这个功能:在工具菜单->选项中,代码工具->Class completion->类的头注释。
The .lpi file contains session information (like caret position and bookmarks of closed units) and the project directory contains a lot of .ppu, .o files and the executable.
+
如果你想显示这些提示,删除空行即可。
To create a lpi file with only the base information and only the sources, along with all sub directories use "Publish Project".
 
  
'''Note''': Since version 0.9.13 there is a new ''Project Option'' that allows you to store session information in a seperate file from the normal .lpi file.  This new file ends with the .lps extension and only contains session information, which will leave you .lpi file much cleaner.
+
下面的注释,GL_TRUE将会显示提示,GL_FALSE不会:
  
In the dialog you can setup the exclude and include filter, and with the command after you can compress the output into one archive.
+
<syntaxhighlight lang=pascal>  // Boolean
 +
  GL_TRUE                          = 1;
 +
  GL_FALSE                          = 0;</syntaxhighlight>

Latest revision as of 01:07, 19 February 2020

Deutsch (de) English (en) español (es) suomi (fi) français (fr) 日本語 (ja) 한국어 (ko) Nederlands (nl) português (pt) русский (ru) slovenčina (sk) 中文(中国大陆)‎ (zh_CN)

Lazarus IDE 工具

概述

IDE使用了Pascal源码解析和编辑工具库,被称为“codetools(代码工具)”。工具提供的功能像查找声明、代码完成、提取、移动插入和美化Pascal。这些函数可以节省你很多时间,你可以在编辑器选项中对它们进行自定义配置。

因为它们的工作时解析FPC、Delphi和Kylix代码。它们不需要编译单元,也不是一个安装了Borland的编译器。你可以在同一时间编辑Delphi和FPC代码。你可以使用不同版本的Delphi和FPC。这使得移植Delphi代码变得容易很多。

IDE 快捷键列表

查找声明 Ctrl+点击 or Alt+ (跳转到声明的类型或变量)
方法跳转 Ctrl+ Shift+ (在定义部分和实现部分进行切换。看见一个定义,就可以用快键方式,直接找到它的实现部分。)
代码模板 Ctrl+J
Syncro 编辑(同步编辑) Ctrl+J (需要选择文本)
类自动完成 Ctrl+ Shift+C
标识符自动完成 Ctrl+空格
关键字自动完成 Ctrl+W
参数提示 Ctrl+ Shift+空格
渐进式搜索 Ctrl+E

方法跳转

要在过程体(begin..end)与过程定义(procedure 过程名)间跳转,使用 Ctrl+ Shift+.

示例:

interface

procedure DoSomething; // 过程定义
 
implementation
 
procedure DoSomething; // 过程体
begin
end;

如果光标在过程体,当你按Ctrl+ Shift+时,会跳转到其定义,再次按Ctrl+ Shift+会跳转到过程体;如此循环。

在方法间(类中的过程)也是如此。

注意: 方法跳转,将跳转到具有相同名称和参数列表的地方,如果没有,它将跳到最佳匹配的地方,并将光标定位在第一个上面。(对于Delphians:Delphi不能做到这一点。)

例如,不同参数类型的过程:

interface

procedure DoSomething(p: char); // 过程定义

implementation
  
procedure DoSomething(p: string); // 过程主体
begin
end;

自定义跳转会在'string'处定位光标,这可用于重命名方法或改变参数。

如:
你更名'DoSomething' 为 'MakeIt':

interface

procedure MakeIt; // 过程定义

implementation

procedure DoSomething; // 过程主体
begin
end;

Then 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.

引入文件

引入文件是使用{$I 文件名} 或 {$INCLUDE 文件名}编译指令。Lazarus和FPC大量采用它,以减少冗余,为考虑平台兼容性,可以使用{$IFDEF}结构。

Contrary 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.

For 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.

But 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.

As 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

{%mainunit yourunit.pas} 

on the top of yourinclude.inc.

This mechanism has of course limits. Some include files are included twice or more. For example: lcl/include/winapih.inc.

Jumping 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. ;)

代码模板

代码模板将标识符转换为文本或代码片段。

默认快捷键是Ctrl+J。输入一个标识符,之后按Ctrl+J键将会替换该标识符为选定的内容。代码模板可以在“工具”菜单->“选项“->“代码工具”里设置。

如,在标识符classf后按Ctrl+Jclassf将被替换为:

T = class(T)
private

public
  constructor Create;
  destructor Destroy; override;
end;

并且光标在T后面。你可以将光标定位在空白位置(而不是标识符那里),按下 Ctrl+J键,将显示代码模板列表。选择一个,将返回选择的代码模板。

输入b之后,按Ctrl+J键,将显示 begin..end; 块。

参数提示

显示参数提示。

例如:

Canvas.FillRect();

将光标置于括号中,按Ctrl+ Shift+space键,将显示FillRect的参数提示信息。

渐进式搜索

渐进式搜索,按Ctrl+E,输入搜索的文本,编辑器会高亮所有搜索到的。

  • 例如,输入e,将搜索并高亮显示所有e的匹配项。
  • 然后,输入t ,将突出显示所有匹配et的文本。
  • 跳转到下一个匹配项,按 F3或(Ctrl+E);跳转到上一匹配项,按 Shift+F3
  • ← Backspace 删除最后一个字符。
  • 停止搜索,可以按 Enter键,或者在代码编辑器中点击鼠标。
  • 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.
  • Ctrl+V键,粘贴剪贴板中的内容到当前搜索(因为lazarus 0.9.27 r19824)。

注意:快速搜索与渐进式搜索的标识符

  • Place text cursor on identifier (do not select anything) 将光标放在标识符处(不要选择任何内容)。
  • Ctrl+C键,将复制选择的标识符到剪贴板。
  • Ctrl+E键,开始渐进式搜索。
  • Ctrl+V键,搜索标识符(自0.9.27)。
  • F3,向下搜索, Shift+F3向下搜索。
  • 使用任意键(如,光标左、右键)来终止搜索。

Syncro 编辑(同步编辑)

Syncro Edit(同步编辑)可以让你在同一时间同步编辑所有匹配到的内容。你简单的在一个地方编辑,所有匹配的内容也会同步更新。


它适用于所有选择区域的文本:

  • 选择文本块。
  • Ctrl+J或,点击编辑左侧显示的“编辑图标”(SyncroEditIcon.png)。按Tab 键,选择要编辑的内容。
  • 输入新内容。
  • Esc键完成编辑。

这里有动画演示

Note-icon.png

Note: Ctrl+J也是代码模板的快捷键,如果你选择的不是文本块的话。

查找下一个/上一个出现的单词

这两个功能,可以在源代码编辑器的弹出菜单中找到:

  • 源代码编辑器 / 弹出菜单 / 查找 / 查找下一个发现的词
  • 源代码编辑器 / 弹出菜单 / 查找 / 查找前一个发现的词

And you can assign them shortcuts in the editor options.你也可以在查找菜单中,找到相应菜单项,它与其功能相同,当然也可以使用快捷键。

代码自动完成

代码自动完成,可以在“编辑”菜单->“自动完成代码”,或按Ctrl+ Shift+C键。(新版的Lazarus,在“Source”菜单->“自动完成代码”)

对于Delphians:

Delphi的“代码完成”,按Ctrl+Space将显示标识符列表。在Lazarus中称为“标识符提示”。

代码自动完成,有多种强大功能:

  • 类完成:自动完成属性,在方法体中增加/更新私有变量或私有方法。
  • 前向引用过程完成: 添加过程体。
  • 事件赋值完成:完成事件赋值,并增加了方法定义和主体。
  • 变量声明完成:增加了局部变量定义。
  • 过程调用完成:添加新过程。
  • 反转过程完成:添加过程/函数体声明。
  • 反转类完成:添加了方法体声明。

这个功能的使用,取决于编辑器中光标的位置,下面进行说明。

类自动完成

(翻译不完善不完整,需要修订)

“类完成”是代码完成中最强大的,编写一个类,添加方法和属性,代码完成,将添加方法休,属性访问方法和变量。

如,创建一个类(见代码模板,以节省你的工作时间):

TExample = class(TObject)
public
  constructor Create;
  destructor Destroy; override;
end;

在类中,按Ctrl+ Shift+C键,将会创建缺少的方法,并将光标移到创建的第一个方法体中,所以,你可以开始编写类代码:

{ TExample }

constructor TExample.Create;
begin
  |
end;

destructor TExample.Destroy;
begin
  inherited Destroy;
end;

留意: '|'是光标位置。

提示:你可以按按Ctrl+ Shift+键,在方法与方法体间跳转。

你可以看到,在IDE中加入了继承销毁,因为,在类中定义了override关键字。

现在,添加一个DoSomething方法:

TExample = class(TObject)
public
  constructor Create;
  procedure DoSomething(i: integer);
  destructor Destroy; override;
end;

Ctrl+ Shift+C,将添加:

procedure TExample.DoSomething(i: integer);
begin
  |
end;

你可以看到新的方法体中插入了创建和销毁,因为在类中已经定义。You can define the insertion policy in Environment > Codetools Options -> Code Creation.

完成属性 添加一个AnInteger属性:

TExample = class(TObject)
public
  constructor Create;
  procedure DoSomething(i: integer);
  destructor Destroy; override;
  property AnInteger: Integer;
end;

Ctrl+ Shift+C将得到:

procedure TExample.SetAnInteger(const AValue: integer);
begin
  |if FAnInteger=AValue then exit;
  FAnInteger:=AValue;
end;

代码完成增加了一个写访问修饰符,并增加了一些常代码,跳转到类,按Ctrl+ Shift+

TExample = class(TObject)
private
  FAnInteger: integer;
  procedure SetAnInteger(const AValue: integer);
public
  constructor Create;
  procedure DoSomething(i: integer);
  destructor Destroy; override;
  property AnInteger: integer read FAnInteger write SetAnInteger;
end;

该属性继承了一个读取和写入访问修饰符,这个类得到了一个新的private(私有)变量FAnInteger和SetAnInteger方法。

It 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.

创建一个只读属性:

property PropName: PropType read;

将它继承:

property PropName: PropType read FPropName;

创建一个只写属性:

 property PropName: PropType write;

将它继承:

property PropName: PropType write SetPropName;

创建一个只读属性与读取方法:

property PropName: PropType read GetPropName;

保持和GetPropName功能:

function GetpropName: PropType;

创建一个属性与存储的修饰符:

property PropName: PropType stored;

将它继承:

property PropName: PropType read FPropName write SetPropName stored PropNameIsStored;

Because stored is used for streaming read and write modifiers are automatically added as well.

提示: 标识符完成允许不完整的属性,并且会提示的默认名称。例如:

property PropName: PropType read |;

将光标置于一个空格的'读'的关键字,然后按Ctrl+Space,它会给出变量'FPropName'和过程'SetPropName“。

前向引用自动完成

前向引用自动完成是代码完成部分,用于添加缺少的过程体。当光标在一个前向定义的过程上时,

例如: 添加一个新过程在接口部分:

procedure DoSomething;

将光标放在声明上,按Ctrl+ Shift+C,这将创建实现部分:

procedure DoSomething;
begin
  |
end;

提示:你可以按Ctrl+ Shift+,在过程定义与过程体间跳转。

如果已经存在过程,新过程体将添加到类方法中,IDE试图保持有序,例如:

 procedure Proc1;
 procedure Proc2; // 新过程
 procedure Proc3;

如果Proc1和Proc3已经存在,那么Proc2部分会在Proc1和Proc3间添加。This behaviour can be setup in Environment > Codetools Options -> Code Creation.

多个过程:

procedure Proc1_Old; // 过程体存在
procedure Proc2_New; // 过程体不存在
procedure Proc3_New; //  "
procedure Proc4_New; //  "
procedure Proc5_Old; // 过程体存在

代码完成,将添加3个过程体:(Proc2_New, Proc3_New, Proc4_New)。

为什么称它是“前向引用自动完成”?

先了解下,前向引用

Because 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.

事件赋值自动完成

事件赋值自动完成,是代码自动完成的一部分,在使用时,将光标放在要赋值事件的后面。

例如,在FormCreate中添加一行:

OnPaint:=
procedure TForm1.Form1Create(Sender: TObject);
begin
  OnPaint:=|
end;

注意:|是光标所在位置。

Ctrl+ Shift+C后,代码将会:

OnPaint:=@Form1Paint;

Form1Paint方法,将被添加到TForm1类中,

procedure TForm1.Form1Paint(Sender: TObject);
begin
  |
end;

这就像在对象观察器中添加方法。

注意:
你必须把光标放在:=后,但如果你将光标放在标识符后,那么将调用代码自动完成。

提示:
你可以自定义方法名,如:

 OnPaint:=@ThePaintMethod;

变量声明自动完成

变量声明自动完成,将未声明的变量对它声明。

如一个局部变量定义:

标识符:=值;

将光标放置在标识符后面。

procedure TForm1.Form1Create(Sender: TObject);
begin
  i:=3;
end;

将光标位在i后,按Ctrl+ Shift+C将得到:

procedure TForm1.Form1Create(Sender: TObject);
var
  i: Integer;
begin
  i:=3;
end;

如果标识符i已经被定义,并且没有添加声明

var i: integer;

标识符的类型,通过赋值运算来得到类型。像数字3默认为整型。

另一个例子:

type
  TWhere = (Behind, Middle, InFront);
 
  procedure TForm1.Form1Create(Sender: TObject);
  var
    a: array[TWhere] of char;
  begin
    for Where:=Low(a) to High(a) do writeln(a[Where]);
  end;

将光标放置在where后,按Ctrl+ Shift+C将得到:

  procedure TForm1.Form1Create(Sender: TObject);
  var
    a: array[TWhere] of char;
    Where: TWhere;
  begin
    for Where:=Low(a) to High(a) do writeln(a[Where]);
  end;

lazarus 0.9.11后将会完成参数:

  procedure TForm1.FormPaint(Sender: TObject);
  begin
    with Canvas do begin
      Line(x1,y1,x2,y2);
    end;
  end;

将光标放置在x1后,按Ctrl+ Shift+C将得到:

  procedure TForm1.FormPaint(Sender: TObject);
  var
    x1: integer;
  begin
    with Canvas do begin
      Line(x1,y1,x2,y2);
    end;
  end;

过程调用自动完成

代码完成可以通过调用语句本身创建一个新程序。假设你刚编写声明

DoSomething(Width);
procedure SomeProcedure;
var
  Width: integer;
begin
  Width:=3;
  DoSomething(Width);
end;

将光标放在标识符DoSomething上,按Ctrl+ Shift+C,将得到:

procedure DoSomething(aWidth: LongInt);
begin

end;

procedure SomeProcedure;
var
  Width: integer;
begin
  Width:=3;
  DoSomething(Width);
end;

它不会创建函数或方法。

反转类自动完成

声明当前私有方法。自Lazarus 0.9.21后可用。

如:

 procedure TForm1.DoSomething(Sender: TObject);
 begin
 end;

DoSomething未被声明,按Ctrl+ Shift+C,将添加TForm1类的私有方法

procedure DoSomething(Sender: TObject);

对于 Delphians:

Lazarus下完成工作始终是:从类接口来实现向后/反转类声明。Delphi是两个方向,但它有个缺点:让你不注意的一个错字会很容易的创建一个方法。

注释和代码自动完成

Code completion tries to keep comments where they belong. For example:

 FList: TList; // list of TComponent
 FInt: integer;

When inserting a new variable between FList and FInt, the comment is kept in the FList line. Same is true for

 FList: TList; { list of TComponent
   This is a comment over several lines, starting
   in the FList line, so codetools assumes it belongs 
   to the FLIst line and will not break this 
   relationship. Code is inserted behind the comment. }
 FInt: integer;

If the comment starts in the next line, then it will be treated as if it belongs to the code below. For example:

 FList: TList; // list of TComponent
   { This comment belongs to the statement below. 
     New code is inserted above this comment and 
     behind the comment of the FList line. }
 FInt: integer;

方法更新

通常类完成将添加缺少的方法体,自0.9.27,如果类中的方法不同,那么方法体将被更新,如你有一个DoSomething方法:

public
    procedure DoSomething;
end;

procedure TForm.DoSomething;
begin
end;

添加一个参数:

  public
    procedure DoSomething(i: integer);
  end;

Ctrl+ Shift+C,该方法声明将被更新,新的参数将被更新:

procedure TForm.DoSomething(i: integer);
begin
end;

重构

互换指派

"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语句互换。

如:

procedure DoSomething;
begin
  AValueStudio:= BValueStudio;
  AValueAppartment :=BValueAppartment;
  AValueHouse:=BValueHouse;
end;

选择要反转的代码,右击选择重构->互换指派”。(或者,Source菜单->重构->互换指派)。

结果:

procedure DoSomething;
begin
  BValueStudio     := AValueStudio;
  BValueAppartment := AValueAppartment;
  BValueHouse      := AValueHouse;
end;

封装所选

选择一些内容,按Ctrl+ Shift+N,会弹出一个对话框,你可以选择一项,之后,会将所选择的内容,括住。

如,你选择了try..finally项,那么,你选择的内容将会被try..finally括住。

你可以在选择内容上右击,源代码->封装所选;或者,Source菜单->封装所选,都可以实现此功能。

重命名标识符

将光标放在标识符上,并调用它(按F2,或右击重构->重命名标识符;也可以在Source菜单->重构->重命名标识符)。

将弹出对话框,输入新的标识符名称,设置搜索范围。

  • It will rename all occurences and only those that actually use this declaration. That means it does not rename declarations with the same name.
  • 它将重命名所有出现,只有那些真正使用这个声明。这意味着它不重命名声明名称相同的。
  • And it will first check for name conflicts.
  • 它将首先检查名称冲突。
  • Limits: It only works on pascal sources, does not yet rename files nor adapt lfm/lrs files nor lazdoc files.
  • 限制:它仅适用于Pascal源文件,还没有重命名的文件,不适用LFM/LRS文件,也不适用,lazdoc文件。

查找标识符参考

将光标放在标识符上,并调用它(按Ctrl+ Shift+I,或右击查找->查找标识符参考;也可以在查找菜单->查找标识符参考);

在出现的对话框中设置搜索范围,IDE将搜索所有出现的,只有那些真正使用这一标识符的,意味着不会显示相同名称的。

显示抽象方法

This 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.

抽取过程

查看 抽取过程

查找声明

将光标定位在要查找声明的标识符上,右击选择查找声明。之后,将搜索并跳转到所选择标识符的定义部分。

Every find declaration sets a Jump Point. That means you jump with find declaration to the declaration and easily jump back with Search -> Jump back.


在Delphi上有些不同:

The 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:

The 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.

可见属性是在TControl (controls.pp)中定义的,然后重新定义TCustomForm在TForm。查找声明时,首先找到TForm,之后再查找时会跳转找到TControl。

像TColor类型,对于编译器它是一个简单的'longint'类型,但在源中其定义是:

TGraphicsColor = -$7FFFFFFF-1..$7FFFFFFF;
TColor = TGraphicsColor;

前向定义类类似,如TControl中,有一个私有变量

FHostDockSite: TWinControl;

查找声明TWinControl,将跳到前向定义。

TWinControl = class;

之后再跳转到真正实现部分

TWinControl = class(TControl)

这样你就可以跟踪每个标识符或查找负载。

提示:

  • Ctrl+H 跳回来
  • 查看所有跳转历史:查看菜单->查看跳转历史
  • With a 5 button Mouse you can use the 2 extra buttons to go forward/backward between the visited points
  • 用5键鼠标,可以使用2个额外的按钮来实现前进/后退光标位置
(你可以使用高级鼠标选项来映射)

标识符自动完成

Ctrl+space调用标识符自动完成,它将显示范围内的所有标识符提示。如:

 procedure TForm1.FormCreate(Sender: TObject);
 begin
   |
 end;

beginend间按Ctrl+space,IDE将分析你的代码,显示所有标识符列表。结果会被缓存,第二次调用时会很快。

Delphians注意::Delphi称为代码完成。

像这些标识符'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.

标识符自动完成,并没有完成所有关键字。所以,人不能用它来完成repe到repeat。对于这些你可以按Ctrl+W关键字自动完成Ctrl+J 代码模板

自0.9.27后,标识符自动完成了,完成了些关键字。

Identifier completion shows even those identifiers, that are not compatible.

前缀

你可以使用一个单词或字母做为前缀,比如说:

 procedure TForm1.FormCreate(Sender: TObject);
 begin
   Ca|ption
 end;

Ca后使用标识符自动完成,将显示所有ca开头的标识符列表。

  • 字母或数字:字符添加到源代码编辑器作为前缀,这将更新列表。
  • 退格键:从前缀中删除一个字符,这将更新列表。
  • Return: replace the whole word at cursor with the selected identifier and close the popup window.
  • Shift+Return: as Return, but replaces only the prefix (left part) of the word at the cursor.
  • 上/下键: 移动选择。
  • ESC键: 不保存信息,关闭弹出对话框。
  • 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'.
  • Else: as Return and add the character to the source editor

方法

当光标在类中定义方法时,使用标识符自动完成会添加相应参数并添加override关键字。例如:

TMainForm = class(TForm)
protected
  mous|
end;

完成的MouseDown

TMainForm = class(TForm)
protected
  procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X,
         Y: Integer); override;
end;

属性

property MyInt: integer read |;

标识符自动完成,将显示FMyIntGetMyInt

property MyInt: integer write |;

标识符自动完成,将显示FMyIntSetMyInt

引用部分/单元名称

In 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).

引用某些单元文件时,使用标识符自动完成,将显示它们的文件路径,文件名通常是小写的(像avl_tree),完成后,会插入像AVL_Tree一样的名称。

语句

procedure TMainForm.Button1Click(Sender: TObject);
begin
  ModalRe|;
end;

变为:

procedure TMainForm.Button1Click(Sender: TObject);
begin
  ModalResult:=|;
end;

关键字自动完成

Ctrl+W键调用关键词自动完成。它显示了当前打开文件中的匹配到的关键词,你也可以在非Pascal源文件中使用,在注释中也可以使用。

否则,它的工作方式等同于标识符自动完成。

Goto Include Directive

"Goto Include Directive" in the search menu of the IDE jumps to {$I filename} statement where the current include file is used.

发布工程

创建项目副本。If you want to send someone just the sources and compiler settings of your code, this function is your friend.

一个项目目录包含了大量信息,很多是不需要再作公布:lpi文件包含了会话信息(像光标位置 、单元书签),项目目录包含了ppu、o及可执行文件。

要发布工程,在工程菜单下使用发布工程。

:0.9.13版本后,有了新的解决方法,它将会话信息存储在了以lps为扩展名的文件里,这样,当你发布时,lpi文件会清爽很多。

在对话框中你可以设置排除列表和过滤器,也可以完成后使用命令压缩成一个档案。

注释提示

在某些地方IDE将显示帮助提示。如,将鼠标移动在一个标识符上等待几秒钟,将显示与此标识符相关的提示信息。

IDE为了支持常见的注释、编程风格,通常会给予试探:

显示注释提示

注释声明中以<开头(没有空行),将作为其上的提示:

var
  {Comment}
  Identifier: integer;

注释在<之后。

与标识符同行的注释:

var 
  identifier, // Comment
  other,

注释和定义在同一行:

var
  identifier: 
    char; // Comment

<示例:

const
  a = 1;
  //< comment for a
  b = 2;
  // comment for c
  c = 3;

支持三种注释方式

  {Comment}(*Comment*)//Comment
  c = 1;

注释中$%将被忽略。

不显示注释信息

用空行分隔的注释,将不会用于提示显示。像下面的类头部注释将不会被显示:

type
  { TMyClass }
  
  TMyClass = class

类头部注释创建于类完成时。你可以关闭这个功能:在工具菜单->选项中,代码工具->Class completion->类的头注释。 如果你想显示这些提示,删除空行即可。

下面的注释,GL_TRUE将会显示提示,GL_FALSE不会:

  // Boolean
  GL_TRUE                           = 1;
  GL_FALSE                          = 0;