xumenger 2015-08-16 15:10 采纳率: 72.2%
浏览 2027
已采纳

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

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

  • 写回答

3条回答 默认 最新

  • lyhoo163 2015-08-17 03:51
    关注

    在过程或函数中,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传递给过程的实际参数不必进行初始化。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog