Difference between revisions of "IDE Window: Extract Procedure/fr"

From Lazarus wiki
Jump to navigationJump to search
Line 17: Line 17:
 
Choisir la ligne "CallSomething;" et lancer la procédure d'extraction. Une boite de dialogue apparaît et
 
Choisir la ligne "CallSomething;" et lancer la procédure d'extraction. Une boite de dialogue apparaît et
 
vous pouvez sélectionner le type et le nom de la procédure à créer. Par exemple :
 
vous pouvez sélectionner le type et le nom de la procédure à créer. Par exemple :
procedure, "NewProc". Result:
+
procedure, "NewProc". Resultat:
 +
<delphi>
 
  procedure NewProc;
 
  procedure NewProc;
 
  begin
 
  begin
Line 27: Line 28:
 
   NewProc;
 
   NewProc;
 
  end;
 
  end;
 +
</delphi>
 
You can see, that the new procedure "NewProc" was created with the selection
 
You can see, that the new procedure "NewProc" was created with the selection
 
as body and the old code was replaced by a call.
 
as body and the old code was replaced by a call.

Revision as of 17:21, 19 July 2007

Deutsch (de) English (en) español (es) suomi (fi) français (fr) русский (ru) slovenčina (sk) 中文(中国大陆)‎ (zh_CN)

Capture d'écran

Edition->Extraire Procédure

ExtraireProcédure.png

Description

Résumé: "Extraire procédure" prend quelques phrases sélectionnées en pascal et crée une nouvelle procédure/méthode à partir de ce code source. Cet outil est utile pour diviser de grosses procédures ou pour créer facilement de nouvelles procédures à partir d'un certain code.

Exemple de base :
<delphi>

procedure DoSomething;
begin
  CallSomething;
end;

</delphi> Choisir la ligne "CallSomething;" et lancer la procédure d'extraction. Une boite de dialogue apparaît et vous pouvez sélectionner le type et le nom de la procédure à créer. Par exemple : procedure, "NewProc". Resultat: <delphi>

procedure NewProc;
begin
  CallSomething;
end;

procedure DoSomething;
begin
  NewProc;
end;

</delphi> You can see, that the new procedure "NewProc" was created with the selection as body and the old code was replaced by a call.

Local Variables and Parameters:
"Extract Proc" scans for used variables and automatically creates the parameter list and local variables. Example:

procedure TForm1.DoSomething(var Erni, Bert: integer);
var
  i: Integer; // Comment
begin
  Erni:=Erni+Bert;
  for i:=Erni to 5 do begin
  |
  end;
end;

Select the for loop and create a new Procedure "NewProc". The local variable i is only used in the selection, so it will be moved to the new procedure. Erni is also used in the remaining code, so it will become a parameter.

Result:

procedure NewProc(const Erni: integer);
var
  i: Integer; // Comment
begin
  for i:=Erni to 5 do begin
  |
  end;
end;

procedure TForm1.DoSomething(var Erni, Bert: integer);
begin
  Erni:=Erni+Bert;
  NewProc(Erni);
end;

You can see "i" was moved to the new procedure (Note: including its comment) and Erni.

Limitations:
Pascal is a very powerful language, so don't expect it will work with every code. Current limits/ToDos:

  • check if selection bounds on statement bounds
  • "with" statements