Difference between revisions of "Basic Pascal Tutorial/Chapter 4/Forward Referencing/zh CN"

From Lazarus wiki
Jump to navigationJump to search
(Created page with "4F - 前向引用 (原作者: Tao Yue, 状态: 未更改) After all these confusing topics, here's something easy. Remember that procedures/functions can only see variables ...")
 
m
Line 1: Line 1:
4F - 前向引用 (原作者: Tao Yue, 状态: 未更改)
+
4F - 向前引用 (原作者: Tao Yue, 状态: 未更改)
  
 
After all these confusing topics, here's something easy.
 
After all these confusing topics, here's something easy.

Revision as of 08:15, 17 December 2013

4F - 向前引用 (原作者: Tao Yue, 状态: 未更改)

After all these confusing topics, here's something easy.

Remember that procedures/functions can only see variables and other subprograms that have already been defined? Well, there is an exception.

If you have two subprograms, each of which calls the other, you have a dilemma that no matter which you put first, the other still can't be called from the first.

To resolve this chicken-and-the-egg problem, use forward referencing.

procedure Later (parameter list); forward;

procedure Sooner (parameter list);
begin
  ...
  Later (parameter list);
end;
...
procedure Later;
begin
  ...
  Sooner (parameter list);
end;

The same goes for functions. Just stick a forward; at the end of the heading.

上一页 目录 下一页