Delphi2009新特性(1):Exit方法

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 i
f
y = 0 then
 Exit(
0);
Result :
= x / y; //如果y等于0,这一行不会被执行 e
nd
;

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

 

原文地址:https://www.cnblogs.com/luckForever/p/7255282.html