Sign in Join
Wiki copytemporary

IDE Window: Extract Procedure/zh CN

Deutsch · English · Español · Français · Slovenčina · Suomi · Русский · 中文(中国)

摘要:选择要抽取的Pascal语句,可以从该代码上创建新过程/方法。这个工具,可以拆分大过程或者创建一个新的过程。

基本示例:

pascal
 procedure DoSomething;
 begin
   CallSomething;
 end;

选择CallSomething,以进行抽取过程(右击,选择重构->解析过程;或者,Source菜单下的重构->解析过程),在弹出的对话框中类型:过程,输入过程名,之后点击抽取。

如,选择上述操作后将返回:

pascal
 procedure NewProc;
 begin
   CallSomething;
 end;
 
 procedure DoSomething;
 begin
   NewProc;
 end;

你可以看到新的NewProc过程被创建和替换。

局部变量和参数:它会自动创建参数列表和局部变量。例如:

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

选择for循环,并创建一个新的过程NewProc。局部变量i仅在使用时选择。所以它会被移到新的程序。Erni会在之后用到,所以作为一个参数。 (右击,选择重构->解析过程;或者,Source菜单下的重构->解析过程),在弹出的对话框中类型:过程,输入过程名,之后点击抽取。

返回结果:

pascal
 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;

你可以看到i被转换到新的过程里,包括注释和Erni。

留意:

Pascal是强大的语言,但不要期望它提取的程序都可以工作。

当前限制和待办:


From the Free Pascal wiki, page "IDE Window: Extract Procedure/zh CN", as it stood on 2020-02-17 after a change by Trev, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's Licensing page. If you have concerns about this material, message the admin.

Revision 1, last changed by WikiArchive .

Edited on wiki.freepascal.org by 2 people, 2014–2020

From the official wiki's backup of 26 May 2024: who edited this page there, and when. Edits made there after that date were not recorded, and the earlier versions are not shown here; the main page says why.

WhenWhoWhat changed
Wangyouworld提取过程
TrevFixed syntax highlighting; deleted category included in page template (minor)

Talk about this page

Nobody has opened a bench for this page yet. Sign in to open one.