• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Delphi函数的out、var等关键字的作用,和使用场景

原作者: [db:作者] 来自: [db:来源] 收藏 邀请
Delphi函数的out、var等关键字的作用,和使用场景

Delphi函数的out、var等关键字的作用,和使用场景,我知道var是作为传值调用,但是像out这个关键字又是什么作用呢?

解决方案

在过程或函数中,out主要用于COM和CORBA技术,Delphi解释:

An out parameter, like a variable parameter, is passed by reference. With an out parameter, however, the initial value of the referenced variable is discarded by the routine it is passed to. The out parameter is for output only; that is, it tells the function or procedure where to store output, but doesn't provide any input.

关键就是“它唯一的用处就是让写过程的程序员提醒一下,这个参数没有什么初始值的,只能给它赋值,而永远不要去用它的值。”

1、相同:var与out修饰的参数,都是通过指针引导的变量参数;它们都可以外出输出值;
2、区别:var修饰的参数,可以带入值,并在过程或函数使用;Out修饰的参数,带入值无效。out传递给过程的实际参数不必进行初始化。 
在过程或函数中,out主要用于COM和CORBA技术,Delphi解释:

An out parameter, like a variable parameter, is passed by reference. With an out parameter, however, the initial value of the referenced variable is discarded by the routine it is passed to. The out parameter is for output only; that is, it tells the function or procedure where to store output, but doesn't provide any input.

关键就是“它唯一的用处就是让写过程的程序员提醒一下,这个参数没有什么初始值的,只能给它赋值,而永远不要去用它的值。”

1、相同:var与out修饰的参数,都是通过指针引导的变量参数;它们都可以外出输出值;
2、区别:var修饰的参数,可以带入值,并在过程或函数使用;Out修饰的参数,带入值无效。out传递给过程的实际参数不必进行初始化。

解决方案二:

out是向外传值,一个函数只有一个返回值,你可以用out把参数当作返回值使用。和var不同,var调用前必须先初始化,而out不需要。

解决方案三:

out只向外面发送,Var可以回传,也可以传入。貌似就这个区别

来源:https://yq.aliyun.com/wenzhang/show_40884


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Matlab 补充知识发布时间:2022-07-18
下一篇:
MATLAB注释快捷键、绘图选项发布时间:2022-07-18
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap