Welcome

首页 / 软件开发 / Delphi / Delphi语言学习5-函数和方法

Delphi语言学习5-函数和方法2011-12-121.函数的定义

//格式
function functionName(parameterList): returnType; directives;
localDeclarations;
begin
statements
end;
//例1
function WF: Integer;
begin
WF := 17;
end;
//例2
function WF: Integer;
begin
Result := 17;
end;
//例3 function MyFunction: Integer;
begin
MyFunction := 5;
Result := Result * 2;
MyFunction := Result + 1;
end;
2.调用方式

Delphi的函数有几种调用方式,

DirectiveParameter orderClean-upPasses parameters in registers?
registerLeft-to-rightRoutineYes
pascalLeft-to-rightRoutineNo
cdeclRight-to-leftCallerNo
stdcallRight-to-leftRoutineNo
safecallRight-to-leftRoutineNo
例如:

function MyFunction(X, Y: Real): Real; cdecl;