Difference between revisions of "Lazarus IDE Tools/ja"

From Free Pascal wiki
Jump to navigationJump to search
Line 97: Line 97:
 
カーソルを空白に置いて(識別子の上でなく)Ctrl+Jを押すとテンプレートのリストがポップアップで示されます。カーソルキーもしくはいくつかの文字をタイプしてその中のどれかを選択してください。リターンキーを押せば選択されたテンプレートが挿入され、Escでそのポップアップが閉じます。
 
カーソルを空白に置いて(識別子の上でなく)Ctrl+Jを押すとテンプレートのリストがポップアップで示されます。カーソルキーもしくはいくつかの文字をタイプしてその中のどれかを選択してください。リターンキーを押せば選択されたテンプレートが挿入され、Escでそのポップアップが閉じます。
  
== コード補完 ==
+
==コード補完==
Code Completion can be found in the IDE menu Edit -> Complete Code and has as standard short cut Ctrl+Shift+C.
+
コード補完はIDEメニューの編集 -> コード補完で呼び出すことができ、標準ショートカットはCtrl+Shift+Cです。
  
For Delphians:
+
Delphiユーザーへ:
Delphi calls "code completion" the function showing the list of identifiers at the current source position (Ctrl+Space). Under Lazarus this is called "Identifier completion".
+
Delphiでは"コード補完"と呼ばれている機能は、現在のソースの位置で(Ctrl+Space)すると識別子のリストが示されるもので、Lazarusでは"識別子補完"と呼ばれているものです。
  
Code Completion combines several powerful functions. Examples:
+
コード補完はいくつかの強力な機能を組み合わせたものです。例:
* Class Completion: completes properties, adds 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
+
* 変数宣言補完: ローカル変数定義を加えます。
  
Which function is used, depends on the cursor position in the editor.
+
どの機能が作動するかはエディタ内のカーソルの位置によります。
  
Code Completion can be found in the IDE menu Edit -> Complete Code and has as standard short cut Ctrl+Shift+C.
+
===クラス補完===
  
===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):
+
TExample = class(TObject)
 
 
TExample = class(TObject)
 
 
  public
 
  public
 
   constructor Create;
 
   constructor Create;
 
   destructor Destroy; override;
 
   destructor Destroy; override;
 
  end;
 
  end;
Position the cursor somewhere in the class and press 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:  
+
カーソルをクラスのどこかに置いてCtrl+Shift+Cしてみてください。メソッドのまだ書かれていない本体が作成され、カーソルを一番上の最初に作成されたメソッド本体に移動させますので、そのままクラスコードを書きはじめることができます:  
  
 
  { TExample }
 
  { TExample }
Line 137: Line 135:
 
   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 Ctrl+Shift+Up.
+
ヒント: 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が'inherited Destroy'呼び出しを追加したことがわかりますね。これはもし'override'キーワードがクラス定義にあれば追加されます。
  
Now add a method DoSomething:  
+
ではDoSomethingメソッドを追加してみましょう:  
  
 
  TExample = class(TObject)
 
  TExample = class(TObject)
Line 151: Line 149:
 
   destructor Destroy; override;
 
   destructor Destroy; override;
 
  end;
 
  end;
Then press Ctrl+Shift+C and the IDE will add
+
ここでCtrl+Shift+Cを押すとIDEは以下を追加します
  
 
  procedure TExample.DoSomething(i: integer);
 
  procedure TExample.DoSomething(i: integer);
Line 157: Line 155:
 
   |
 
   |
 
  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.
+
クラス定義と同じくCreateとDestroyの間に新しいメソッド本体が挿入されたのがわかりますね。このようにして本体はあなたが定義したのと同じ論理的順序で作成されます。挿入ポリシーは、環境 -> コードツールオプション -> コード作成で設定できます。
  
'''Complete Properties'''<br>
+
'''プロパティの補完'''
Add a property AnInteger:
+
プロパティAnIntegerを加えましょう:
 
  TExample = class(TObject)
 
  TExample = class(TObject)
 
  public
 
  public
Line 168: Line 166:
 
   property AnInteger: Integer;
 
   property AnInteger: Integer;
 
  end;
 
  end;
Press Ctrl+Shift+C and you will get:
+
Ctrl+Shift+Cを押すと、次のようになります:
 
  procedure TExample.SetAnInteger(const AValue: integer);
 
  procedure TExample.SetAnInteger(const AValue: integer);
 
  begin
 
  begin
Line 174: Line 172:
 
   FAnInteger:=AValue;
 
   FAnInteger:=AValue;
 
  end;
 
  end;
The code completion has added a Write access modifier and added some common code.
+
コード補完はWriteアクセス指定子と数行の共通コードを追加しました。
Jump to the class with Ctrl+Shift+Up to see the new class:
+
新しいクラスを見るにはCtrl+Shift+Upでそのクラスに移動します。
 
  TExample = class(TObject)
 
  TExample = class(TObject)
 
  private
 
  private
Line 186: Line 184:
 
   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'.
 
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:
+
そのプロパティにReadとWriteアクセス指定子が追加されています。そのクラスはFAnInteger変数と'SetAnInteger'メソッドを有する'private'という新しいセクションを得ました。
 +
変数に接頭文字F、メソッドにSetを付けるのはDelphiの共通スタイル規則です。もしこれがお気に召さなければ、環境 > コードツールオプション -> コード補完でこれを変更できます。
 +
 
 +
 
 +
読み込み専用プロパティを作成する場合:
 
  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:
+
Read メソッドを持つ読み込み専用プロパティを作成する場合:
 
  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:
+
stored指定子を持つプロパティを作成する場合:
 
  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.
+
storedはストリーミングに用いられるため、readとwrite指定子が同様に自動的に追加されます。
  
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'.
+
カーソルを'read'キーワードより1スペース後ろに置き、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 Ctrl+Shift+C for code completion. It will create in the implementation section:
+
カーソルをその上に置き、Ctrl+Shift+Cを押してコード補完を呼び出すと、実行部が作成されます:
 
  procedure DoSomething;
 
  procedure DoSomething;
 
  begin
 
  begin
 
   |
 
   |
 
  end;
 
  end;
Hint: You can jump between a procedure definition and its body with Ctrl+Shift+Up.
+
ヒント: 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; // 新しい proc
 
   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.
+
もしProc1とProc3の本体が既に存在すれば、Proc2の本体はProc1とProc3の間に挿入されます。この動作は環境 -> コードツールオプション ->コード作成 で設定できます。
  
 
Multiple procedures:
 
Multiple procedures:
  procedure Proc1_Old; // body exists
+
  procedure Proc1_Old; // 本体が存在
  procedure Proc2_New; // body does not exists
+
  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"?
+
なぜそれを前方手続き補完と呼ぶのでしょうか?
  
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.
+
なぜならそれは宣言部に定義された手続きにのみ作用するのではなく、"forward" 指定子をもつ手続きにも同様に作用するからです。そしてそのコードツールが宣言部内の暗黙の'forward' 指定子をもつ手続きを扱うからです。
  
===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.
 
  
For example:
+
===イベント 代入補完===
In a method, say the FormCreate event, add a line 'OnPaint:=':
+
"イベント代入補完"はコード補完機能の一部で、単一のイベント:=| 文を補います。これはカーソルがイベントへの代入のすぐ後ろにあるときに呼び出されます。
 +
 
 +
:
 +
あるメソッド, 例えばFormCreateイベントで、'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
+
ここで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>
+
注意:
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.
+
カーソルは':='代入の後ろに置いてください。カーソルをその識別子 (e.g. OnPaint)の上に置いた場合、 コード補完は"ローカル変数補完"を呼び出してしまいます(そしてそれは失敗します。なぜならOnPaintは既に宣言されているから)。
  
Hint:<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.
+
"変数宣言補完"もコード補完の一部で、ローカル変数定義を識別子:=Term; 文に追加します。これはカーソルが代入識別子もしくは変数の上にある時に呼び出せます。
  
For example:
+
:
 
  procedure TForm1.Form1Create(Sender: TObject);
 
  procedure TForm1.Form1Create(Sender: TObject);
 
  begin
 
  begin
 
   i:=3;
 
   i:=3;
 
  end;
 
  end;
Place the cursor on the 'i' or just behind it. Then press Ctrl+Shift+C for code completion and you will get:
+
カーソルを i もしくはその後ろに置いてみて下さい。それからCtrl+Shift+Cを押してコード補完を呼び出すと次のようになります:
 
  procedure TForm1.Form1Create(Sender: TObject);
 
  procedure TForm1.Form1Create(Sender: TObject);
 
  var
 
  var
Line 284: Line 287:
 
   i:=3;
 
   i:=3;
 
  end;
 
  end;
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.
+
このコードツールはまず識別子 i が既に定義されているかどうかをチェックし、もしなかったら宣言 'var i: integer;'を追加します。識別子の型は代入 ':=' 演算子の右辺から推測されます。3のような数値はデフォルトでIntegerと判断されます。
  
Another example:
+
もうひとつの例:
 
type
 
type
 
   TWhere = (Behind, Middle, InFront);
 
   TWhere = (Behind, Middle, InFront);
Line 296: Line 299:
 
     for Where:=Low(a) to High(a) do writeln(a[Where]);
 
     for Where:=Low(a) to High(a) do writeln(a[Where]);
 
   end;
 
   end;
Place the cursor on 'Where' and press Ctrl+Shift+C for code completion. You get:
+
カーソルをWhereの上に置き、 Ctrl+Shift+Cで コード補完を呼び出すと、次のようになります:
 
   procedure TForm1.Form1Create(Sender: TObject);
 
   procedure TForm1.Form1Create(Sender: TObject);
 
   var
 
   var
Line 305: Line 308:
 
   end;
 
   end;
  
Since 0.9.11 Lazarus also completes parameters. For example
+
0.9.11以降Lazarusは引数も補完できるようになりました。
 +
例:
 
   procedure TForm1.FormPaint(Sender: TObject);
 
   procedure TForm1.FormPaint(Sender: TObject);
 
   begin
 
   begin
Line 312: Line 316:
 
     end;
 
     end;
 
   end;
 
   end;
Place the cursor on 'x1' and press Ctrl+Shift+C for code completion. You get:
+
カーソルをx1の上に置き、Ctrl+Shift+Cでコード補完を呼び出すと、次のようになります:
 
   procedure TForm1.FormPaint(Sender: TObject);
 
   procedure TForm1.FormPaint(Sender: TObject);
 
   var
 
   var
Line 322: Line 326:
 
   end;
 
   end;
  
===Comments and Code Completion===
+
===コメントとコード補完===
Code completion tries to keep comments where they belong.
+
コード補完はコメントをそれが属する場所に留めようとします。
For example:
+
:
   FList: TList; // list of TComponent
+
   FList: TList; //TComponentのリスト
 
   FInt: integer;
 
   FInt: integer;
When inserting a new variable between FList and FInt, the comment is kept in the FList line. Same is true for
+
新しい変数をFListとFIntの間に挿入しようとすると、そのコメントはFListの行に保たれます。これは次のような場合にも同様です。
   FList: TList; { list of TComponent
+
   FList: TList; {TComponentのリスト
     This is a comment over several lines, starting
+
     これはFListの行から始まる数行に渡るコメントで、
     in the FList line, so codetools assumes it belongs
+
     コードツールはこれがFListの行に属するものとして
     to the FLIst line and will not break this
+
     扱い、この関係を壊しません。コードはこのコメントの
     relationship. Code is inserted behind the comment. }
+
     後ろに挿入されます。}
 
   FInt: integer;
 
   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
 
   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. }
+
       FListの行の後に挿入されます。}
 
   FInt: integer;
 
   FInt: integer;
  

Revision as of 14:24, 18 September 2006

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 Documentation日本語版 - 翻訳ノート - 日本語障害情報


概要

IDEは"コードツール"と呼ばれる、pascalソースの構文解析と編集のためのツールのライブラリを使用しています。これらのツールは宣言の探索、コード補完、抽出、pascalのソースの移動・挿入、美化といった機能を提供します。これらの機能は、多くの時間の節約につながり、効率を倍加させてくれます。これらはカスタマイズでき、どの機能もショートカットで利用できます(エディタオプションを見てください)。それらの機能はソースにのみ作用し、fpcやdelphiやkylixコードを解釈するだけなので、コンパイルされたユニットやBorlandコンパイラを必要としません。 あなたはDelphiとFPCコードを同時に編集できます。あなたはいくつかのバージョンのDelphiとFPCコードに同時に取り組むことさえできます。このことがDelphiコードの移植をより容易にします。

IDE ショートカットの要約テーブル

宣言への移動 Ctrl+Click or Alt+Up (型や変数の宣言への移動)
メソッドへの移動 Ctrl+Shift+Up (宣言と本体との切り替え)
コードテンプレート Ctrl+J
コード補完 (クラス補完) Ctrl+Shift+C
識別子補完 Ctrl+Space
語句補完 Ctrl+W

メソッドへの移動

手続きの本体(begin..end)と手続き宣言(procedure Name;)の間の移動にはCtrl+Shift+Upを用いてください。 例えば:

interface

procedure DoSomething; // procedure definition
 
implementation
 
procedure DoSomething; // 手続き本体 
begin
end;

カーソルが手続きの本体にあるときにCtrl+Shift+Upすると、カーソルが手続き宣言に移動します。もう一度 Ctrl+Shift+Upを押すと本体のbeginのあとに移動します。 この機能はメソッド(クラスの手続き)でも使えます。

ヒント: 'メソッドへの移動'は同じ名前と引数リストをもつ同じ手続きに移動します。もし合致する手続きがなければ最良の候補の中の最初に異なる部分に移動します。(Delphiユーザーへ: Delphiにはない機能です).

異なる引数型をもつ手続きの例:

interface

procedure DoSomething(p: char); // procedure definition

implementation
  
procedure DoSomething(p: string); // 手続き本体
begin
end;

宣言から本体に移動するとカーソルはキーワード'string'に移動します。これはメソッドの名称変更や引数の変更のさいに便利です。

例: 'DoSomething'を 'MakeIt'に変更した場合:

interface

procedure MakeIt; // 手続きの定義

implementation

procedure DoSomething; // 手続きの本体
begin
end;

このときMakeItから本体に移動します。IDEは一致する本体を探し、それが見付からないので候補を探します。あなたが名称変更した手続きは一つしかないので、宣言(DoSomething)のない本体はひとつしかなく、したがってDoSomethingに移動し、'DoSomething'のすぐ右側にカーソルが置かれます。ですからその名前も同様に変更すればいいわけです。この機能は引数についても同様です。

インクルードファイル

インクルードファイルはコンパイラ指令{$I filename} もしくは {$INCLUDE filename} でソースに挿入されるファイルです。異なるプラットフォームをサポートするため、LazarusとFPCは、冗長になることを防ぎ、読みにくい{$IFDEF}構造体を避けるためにインクルードファイルはコンパイラ指令を用いています。

例えば、.pasファイルの中のメソッドからインクルードファイル内のメソッド本体へ移動できます。 コード補完のようなすべてのコードツールはインクルードファイルを特殊な拘束条件とみなします。

例:コード補完がもうひとつのメソッド本体のうしろに新しいメソッドを追加すると、コード補完は双方を同じファイル内に保持します。このようにして、LCLがほぼ全てのコントロールにそうやって管理しているのと同様に、すべてのクラス実装をインクルードファイル内に置くことができます。 しかし、初心者が陥りやすい罠があります: インクルードファイルを最初に開き、メソッド移動もしくは定義検索をしようとすると、エラーが発生します。IDEはどのユニットにインクルードファイルが属するかを知りません。まず初めに対象とするユニットを開かなければなりません。


IDEがユニットを構文解析するとすぐに、そこのインクルード指令を解釈し、IDEはこの関係を記憶します。IDEはこの情報を終了時やプロジェクト保存時に‾/.lazarus/includelinks.xmlに保存します。次にこのインクルードファイルを開き、移動や定義検索をしようとすると、IDEは内部的にそのユニットを開き、移動機能が作動します。

このメカニズムにはもちろん限界があります。いくつかのインクルードファイルは2回かそれ以上インクルードされます。例: lcl/include/winapih.inc.

このインクルードファイルの手続きもしくはメソッド定義からその本体への移動は直前の動作次第です。もしlcl/lclintf.ppに取り組んでいるのであれば、IDEはwinapi.incに移動します。もしlcl/interfacebase.ppを扱っているのであれば、IDEはlcl/include/interfacebase.inc (もしくはその他のインクルードファイル)に移動します。それらの両方に取り組んでいるのであれば...混乱してしまいますね ;)

コードテンプレート

コードテンプレートは、ある識別子からあるテキストもしくはコードの断片に変換します。 コードテンプレートのデフォルトのショートカットはCtrl+Jです。識別子をタイプして、Ctrl+Jを押すと識別子は識別子に応じて設定されたテキストに置き換えられます。コードテンプレートは環境 -> コードテンプレートで設定できます。

例: 識別子'classf'を書き、カーソルをfのすぐ後ろに置いて、Ctrl+Jを押すと、'classf'は以下に置き換えられます。

T = class(T)
private

public
  constructor Create;
  destructor Destroy; override;
end;

そしてカーソルは'T'の後ろに来ます。 カーソルを空白に置いて(識別子の上でなく)Ctrl+Jを押すとテンプレートのリストがポップアップで示されます。カーソルキーもしくはいくつかの文字をタイプしてその中のどれかを選択してください。リターンキーを押せば選択されたテンプレートが挿入され、Escでそのポップアップが閉じます。

コード補完

コード補完はIDEメニューの編集 -> コード補完で呼び出すことができ、標準ショートカットはCtrl+Shift+Cです。

Delphiユーザーへ: 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+Upでメソッドとその本体とを移動移動できます。

IDEが'inherited Destroy'呼び出しを追加したことがわかりますね。これはもし'override'キーワードがクラス定義にあれば追加されます。

ではDoSomethingメソッドを追加してみましょう:

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

ここでCtrl+Shift+Cを押すとIDEは以下を追加します

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

クラス定義と同じくCreateとDestroyの間に新しいメソッド本体が挿入されたのがわかりますね。このようにして本体はあなたが定義したのと同じ論理的順序で作成されます。挿入ポリシーは、環境 -> コードツールオプション -> コード作成で設定できます。

プロパティの補完 プロパティ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;

コード補完はWriteアクセス指定子と数行の共通コードを追加しました。 新しいクラスを見るにはCtrl+Shift+Upでそのクラスに移動します。

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;

そのプロパティにReadとWriteアクセス指定子が追加されています。そのクラスはFAnInteger変数と'SetAnInteger'メソッドを有する'private'という新しいセクションを得ました。 変数に接頭文字F、メソッドにSetを付けるのはDelphiの共通スタイル規則です。もしこれがお気に召さなければ、環境 > コードツールオプション -> コード補完でこれを変更できます。


読み込み専用プロパティを作成する場合:

property PropName: PropType read;

が以下のように拡張されます。

property PropName: PropType read FPropName;

書き込み専用プロパティを作成する場合:

 property PropName: PropType write;

が以下のように拡張されます。

property PropName: PropType write SetPropName;

Read メソッドを持つ読み込み専用プロパティを作成する場合:

property PropName: PropType read GetPropName;

これはそのままで、GetPropName関数が追加されます:

function GetpropName: PropType;

stored指定子を持つプロパティを作成する場合:

property PropName: PropType stored;

が次のように拡張されます。

property PropName: PropType read FPropName write SetPropName stored PropNameIsStored;

storedはストリーミングに用いられるため、readとwrite指定子が同様に自動的に追加されます。

ヒント: 識別子補完は不完全なプロパティも認識し、デフォルトの名前を提案します。例:

property PropName: PropType read |;

カーソルを'read'キーワードより1スペース後ろに置き、Ctrl+Spaceを押すと識別子補完が作動します。識別子補完は変数'FPropName'と手続き'SetPropName'を提案します。


前方手続き補完

"前方手続き補完"はコード補完機能の一部で、不足している手続き本体を追加します。カーソルが前方に定義された手続き宣言の上にあるときに有効となります。

例: 宣言部に新しい手続き宣言を追加します:

procedure DoSomething;

カーソルをその上に置き、Ctrl+Shift+Cを押してコード補完を呼び出すと、実行部が作成されます:

procedure DoSomething;
begin
  |
end;

ヒント: Ctrl+Shift+Upでメソッドとその本体とを移動移動できます。

新しい手続き本体がクラスメソッドの前に追加されます。もし宣言部に既にいくつかの手続きがあれば、IDEはその順序を維持しようとします。 例:

 procedure Proc1;
 procedure Proc2; // 新しい proc
 procedure Proc3;

もしProc1とProc3の本体が既に存在すれば、Proc2の本体はProc1とProc3の間に挿入されます。この動作は環境 -> コードツールオプション ->コード作成 で設定できます。

Multiple procedures:

procedure Proc1_Old; // 本体が存在
procedure Proc2_New; // 本体がまだない
procedure Proc3_New; //  "
procedure Proc4_New; //  "
procedure Proc5_Old; // 本体が存在

コード補完は3つの手続き本体 (Proc2_New, Proc3_New, Proc4_New)を追加します。

なぜそれを前方手続き補完と呼ぶのでしょうか?

なぜならそれは宣言部に定義された手続きにのみ作用するのではなく、"forward" 指定子をもつ手続きにも同様に作用するからです。そしてそのコードツールが宣言部内の暗黙の'forward' 指定子をもつ手続きを扱うからです。


イベント 代入補完

"イベント代入補完"はコード補完機能の一部で、単一のイベント:=| 文を補います。これはカーソルがイベントへの代入のすぐ後ろにあるときに呼び出されます。

例: あるメソッド, 例えばFormCreateイベントで、'OnPaint:='という行を追加してみます:

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

'|'はカーソルを表しており、タイプすべきものではありません。 ここでCtrl+Shift+Cと押してコード補完を呼び出します。その文は次のように補完されます。

OnPaint:=@Form1Paint;

新しいメソッドForm1PaintがTForm1クラスに追加されます。それからクラス補完が作動し、次のようになります:

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

これはちょうどオブジェクトインスペクタでメソッドを追加するような動作です。

注意: カーソルは':='代入の後ろに置いてください。カーソルをその識別子 (e.g. OnPaint)の上に置いた場合、 コード補完は"ローカル変数補完"を呼び出してしまいます(そしてそれは失敗します。なぜならOnPaintは既に宣言されているから)。

ヒント: 新しいメソッド名をあなた自身で定義することもできます。例えば:

 OnPaint:=@ThePaintMethod;

変数宣言補完

"変数宣言補完"もコード補完の一部で、ローカル変数定義を識別子:=Term; 文に追加します。これはカーソルが代入識別子もしくは変数の上にある時に呼び出せます。

例:

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のような数値はデフォルトでIntegerと判断されます。

もうひとつの例: 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;

0.9.11以降Lazarusは引数も補完できるようになりました。 例:

 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;

コメントとコード補完

コード補完はコメントをそれが属する場所に留めようとします。 例:

 FList: TList; //TComponentのリスト
 FInt: integer;

新しい変数をFListとFIntの間に挿入しようとすると、そのコメントはFListの行に保たれます。これは次のような場合にも同様です。

 FList: TList; {TComponentのリスト
   これはFListの行から始まる数行に渡るコメントで、
   コードツールはこれがFListの行に属するものとして 
   扱い、この関係を壊しません。コードはこのコメントの 
   後ろに挿入されます。}
 FInt: integer;

コメントが次の行から始まっている場合、それはそれがそれ以下のコードに属するものとして扱われます。 例:

 FList: TList; // list of TComponent
   {このコメントはこれ以下に属します。 
     新しいコードはこのコメントの上で、
     FListの行の後に挿入されます。}
 FInt: integer;

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.

Example:

procedure DoSomething;
begin
  AValueStudio:= BValueStudio;
  AValueAppartment :=BValueAppartment;
  AValueHouse:=BValueHouse;
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:

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

Extract Procedure

See Extract Procedure

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.

There are some differences to 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.

Same is true for types like TColor. For the compiler it is simply a 'longint'. But in the sources it is defined as

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

And the same for forward defined classes: For instance in TControl, there is a private variable

FHostDockSite: TWinControl;

Find declaration on TWinControl jumps to the forward definition

TWinControl = class;

And invoking it again jumps to the real implementation

TWinControl = class(TControl)

This way you can track down every identifier and find every overload.

Hints: You can jump back with Ctrl+H.

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.

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.

A normal project directory contains a lot of information. Most of it is not needed to be published: 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.

In the dialog you can setup the exclude and include filter, and with the command after you can compress the output into one archive.

Original contributors

This page has been converted from the epikwiki version.

  • Created page and initial template - 4/6/2004 VlxAdmin
  • Initial content posted - 4/10/2004 MattiasG
  • Small wiki and formatting fixes - 4/11/2004 VlxAdmin
  • Added a summary table for IdeTools shortcuts - 12 July 2004 User:Kirkpatc