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 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 关于#python#的问题:自动化测试