Sign in Join
Wiki copytemporary

IDE Window: Extract Procedure/zh CN: what changed

Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.

Title: IDE Window: Extract Procedure/zh CN

OldNewLine
1+摘要:选择要抽取的Pascal语句,可以从该代码上创建新过程/方法。这个工具,可以拆分大过程或者创建一个新的过程。
2+
3+基本示例:
4+
5+``` pascal
6+ procedure DoSomething;
7+ begin
8+ CallSomething;
9+ end;
10+```
11+
12+选择CallSomething,以进行抽取过程(右击,选择重构-\>解析过程;或者,Source菜单下的重构-\>解析过程),在弹出的对话框中类型:过程,输入过程名,之后点击抽取。
13+
14+如,选择上述操作后将返回:
15+
16+``` pascal
17+ procedure NewProc;
18+ begin
19+ CallSomething;
20+ end;
21+
22+ procedure DoSomething;
23+ begin
24+ NewProc;
25+ end;
26+```
27+
28+你可以看到新的NewProc过程被创建和替换。
29+
30+局部变量和参数:它会自动创建参数列表和局部变量。例如:
31+
32+``` pascal
33+ procedure TForm1.DoSomething(var Erni, Bert: integer);
34+ var
35+ i: Integer; // Comment
36+ begin
37+ Erni:=Erni+Bert;
38+ for i:=Erni to 5 do begin
39+ |
40+ end;
41+ end;
42+```
43+
44+选择for循环,并创建一个新的过程NewProc。局部变量i仅在使用时选择。所以它会被移到新的程序。Erni会在之后用到,所以作为一个参数。 (右击,选择重构-\>解析过程;或者,Source菜单下的重构-\>解析过程),在弹出的对话框中类型:过程,输入过程名,之后点击抽取。
45+
46+返回结果:
47+
48+``` pascal
49+ procedure NewProc(const Erni: integer);
50+ var
51+ i: Integer; // Comment
52+ begin
53+ for i:=Erni to 5 do begin
54+ |
55+ end;
56+ end;
57+
58+ procedure TForm1.DoSomething(var Erni, Bert: integer);
59+ begin
60+ Erni:=Erni+Bert;
61+ NewProc(Erni);
62+ end;
63+```
64+
65+你可以看到i被转换到新的过程里,包括注释和Erni。
66+
67+留意:
68+
69+Pascal是强大的语言,但不要期望它提取的程序都可以工作。
70+
71+当前限制和待办:
72+
73+- 检查语句选择范围
74+- with语句
75+
76+---
77+*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](/wiki-contact).*

Back to history