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

问题描述

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

转载于:https://www.cnblogs.com/railgunman/p/8627572.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值