Delphi2009新特性(1):Exit方法

在函数中,使用Result作为返回变量,必须要等所有代码执行完成

function TForm1.abc(x, y: Integer): Integer;
begin
  if y = 0 then
    Result := 0
  else
    Result := x / y;

end;

Delphi 2009,新增了Exit方法,指定返回值,同时退出函数

function TForm1.abc(x, y: Integer): Integer;
begin
  if y = 0 then
    Exit(0);

  Result := x / y; //如果y等于0,这一行不会被执行

end;

 

Exit方法,和C系语言的return的作用基本是一致的。

 

posted @ 2013-02-21 16:57  静候良机  阅读(811)  评论(0编辑  收藏  举报