IDE Window: Extract Procedure/zh CN
Deutsch · English · Español · Français · Slovenčina · Suomi · Русский · 中文(中国)
摘要:选择要抽取的Pascal语句,可以从该代码上创建新过程/方法。这个工具,可以拆分大过程或者创建一个新的过程。
基本示例:
procedure DoSomething;
begin
CallSomething;
end;选择CallSomething,以进行抽取过程(右击,选择重构->解析过程;或者,Source菜单下的重构->解析过程),在弹出的对话框中类型:过程,输入过程名,之后点击抽取。
如,选择上述操作后将返回:
procedure NewProc;
begin
CallSomething;
end;
procedure DoSomething;
begin
NewProc;
end;你可以看到新的NewProc过程被创建和替换。
局部变量和参数:它会自动创建参数列表和局部变量。例如:
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菜单下的重构->解析过程),在弹出的对话框中类型:过程,输入过程名,之后点击抽取。
返回结果:
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是强大的语言,但不要期望它提取的程序都可以工作。
当前限制和待办:
- 检查语句选择范围
- with语句
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.