Delphi 10.3新特性 内联变量


本文整理自网络,侵删。

 
简单一句话:Delphi 终于不用非将变量定义在函数的开头位置了。

拓展开来:

1、您可以在代码中使用变量时,通过下面的格式来定义变量:

var 变量名[:变量类型][:=变量值]

示例一:

procedureTest;
begin
 varI,J:Integer;
 I:=22;
 j:=I+20;
 ShowMessage(J.ToString);
end;
示例2:


procedureTest;// declaration and initialization in a single statement
begin
 varI:Integer:=22;
 ShowMessage(I.ToString);
end;
示例3:

procedureTest1;// multiple inline declarations (symbols declared when used)
begin
 varI:Integer:=22;
 varJ:Integer:=22+I;
 varK:Integer:=I+J;
 ShowMessage(K.ToString);
end;
2、内联变量的生命周期和C++一样,仅在方寸之间,如 begin/end 之间,循环体内等。

3、如果不指类变量的类型,会根据赋值的类型进行推断,相当于 C++ 的 auto 类型。

4、常量也可以内联了,只不过将 var 换成 const ,其它一致。

简译自 Macro 技术博客

相关阅读 >>

Delphi twebbrowser:确定带有框架的页面何时完成

rightstr 返回字符串右边指定个数的新字符(串)

Delphi 返回下载地址的文件名

Delphi firedac tfdconnection连接mysql数据库

Delphi 实现dns上线域名解析(用于远控server)

Delphi 在ms access数据库中图像的存储和显示

Delphi 读写附加数据

Delphi sysutils.stringreplace - 替换

Delphi 字符串反转函数

Delphi 控制n个字符间距空格

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...