类型的全局变量,你可以这样声明一个常量
const PI: ^Integer = @I;
因为全局变量是代码段(code segment)的一部分,编译器能解析它的值,函数和全局常量也是一样。const PF: Pointer = @MyFunction; Integer
- 77 - 是一个
Data types, variables and constants
因为常量字符串被当作全局常量进行分配,所以你能使用常量字符串来初始化一个PChar常量: const WarningStr: PChar = 'Warning!';
局部变量(在堆栈中分配)和动态变量(在堆中分配)的地址不能赋给指针常量。
- 78 -
Procedures and functions
Procedures and functions(过程和函数)
Procedures and functions: Overview(概述)
过程和函数统称为例程(routine),它们是自包含的语句块,能在程序的不同地方调用。函数在在执行时能返回一个值,而过程不能。
因为函数调用能返回值,它们能被用在赋值和运算表达式中。比如,
I := SomeFunction(X);
调用SomeFunction并且把它的结果赋给I。函数调用不能出现在赋值语句的左边。
过程调用能被用作一个完整的语句,并且,当启用扩展语法时({$X+}),函数调用也可以。比如, DoSomething;
调用DoSomething例程,若DoSomething是一个函数,它的返回值被忽略。
过程和函数能递归调用。
Declaring procedures and functions(声明过程和函数) Declaring procedures and functions: Overview(概述)
声明过程或函数时,要指定它的名称,它使用的参数(数目和类型),如果是函数的话,还有返回值的类型,这一部分有时被称为原型、标题或头(prototype、heading、header)。然后你为它写一个代码块,当过程或函数被调用时,它们将会执行。这一部分有时称为例程体或例程块(body、block)。
标准过程Exit可出现在任何过程或函数中,它结束例程的执行,并立即把程序控制返回到例程调用的地方。
Procedure declarations(过程声明)
一个过程声明有如下格式:
procedure procedureName(parameterList); directives;
localDeclarations;
begin
statements
end;
这里,procedureName是任何有效标志符;statements是一系列语句,当调用过程时它们被执行;(parameterList)、directives; 和localDeclarations是可选的。
? 要了解parameterList的信息,请参考Parameters;
? 要了解directives的信息,请参考Calling conventions、Forward and intece declarations、External
declarations、 Overloading procedures and functions、和Writing dynamically loadable libraries。如果包含多个指示字,用分号把它们隔开;
? localDeclarations定义局部标志符,要了解它的信息,请参考Local declarations。
本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/jisuanjixue/article-23665-55.html
很喜欢舒淇