过程和函数:
区别:函数可以有返回值, 过程没有返回值
//函数
function GetApplicationPath(ShowResult: Boolean) :string; //函数内有个预定义的Result 作为返回值 口号后面为函数返回类型
begin
Result := ParaStr(0); //获得程序路径
Result := ExtractFilePath(Result);//获得程序的绝对路径
if showResult then
ShowMessage('应用程序路径是:' + Result);
end;
//过程
procedure showInfo(Info: String);
begin
ShoeMessage('程序路径是:' + Info);
end;
子过程:
子过程只在目过程中有效
区别:函数可以有返回值, 过程没有返回值
//函数
function GetApplicationPath(ShowResult: Boolean) :string; //函数内有个预定义的Result 作为返回值 口号后面为函数返回类型
begin
Result := ParaStr(0); //获得程序路径
Result := ExtractFilePath(Result);//获得程序的绝对路径
if showResult then
ShowMessage('应用程序路径是:' + Result);
end;
//过程
procedure showInfo(Info: String);
begin
ShoeMessage('程序路径是:' + Info);
end;
子过程:
子过程只在目过程中有效