那种编译器实现了pascal的函数参数和过程参数功能?
Turbo pascal、Free pascal和delphi7都没有实现,以用就说function非法。
[解决办法]
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;
type
TForm1 = class(TForm)
private
{ Private declarations }
function xyz(x:integer):boolean;//定义一个类的"私有"函数、整型参数、返回布尔型值
public
{ Public declarations }
function abc(x:integer):boolean;//定义一个类的"公开"函数、整型参数、返回布尔型值
end;
var
Form1: TForm1;
function cdef(y:string):integer;//定义一个单元的"公开"函数、字符串参数、返回整型值
implementation
//函数 abc、cdef 可被外部单元引用,函数 xyz、hijk不能被外部单元引用。
//单元或类的过程,除无返回外,定义和编写过程体,与本例函数方法相同。
//单元或类的变量定义,摆放位置与本例函数定义的摆放位置同义。
{$R *.dfm}
function hijk(z:boolean):string;//省略定义的函数体(此为单元内私有函数),必须放在引用该函数的语句之前
begin
Result := 'False';
if z then Result := 'True';
end;
function TForm1.xyz(x: integer): boolean;//类的函数体,需在函数名前有类名作前导
begin
Result := false;
//......
end;
function TForm1.abc(x: integer): boolean;//类的函数体,需在函数名前有类名作前导
begin
Result := false;
//......
end;
function cdef(y:string):integer;//单元的函数,函数名前不需类名作前导
begin
Result := 0;
showmessage(hijk(true));//此处引用了一个省略定义的函数(该类函数或过程,须摆放在此之前!)
//......
end;
end.