Basic Pascal Tutorial/Chapter 4/Forward Referencing/zh CN

From Lazarus wiki
(Redirected from Forward Referencing/zh CN)
Jump to navigationJump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

български (bg) English (en) français (fr) 日本語 (ja) 中文(中国大陆)‎ (zh_CN)

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

这些虽然容易理解,但有时也让人困惑。

程序中只能使用已经定义的过程/函数?或许是这样吧,先定义后使用。

不过,也有例外,你想先使用后定义?要解决这类问题,你需要使用前向引用。(在预先声明的过程/函数后加forward)

如:

procedure Later (参数列表); forward;

procedure Sooner (参数列表);
begin
  ...
  Later (参数列表);
end;
...
procedure Later;
begin
  ...
  Sooner (参数列表);
end;


示例:

program q;

procedure a;forward;

procedure b;
begin
    writeln('B调取A:');
    a;
end;

procedure a;
begin
    writeln('A过程.');
end;

begin
    b;
end.

相关

维基百科前向声明

上一页 目录 下一页