zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    前端项目升级和降级依赖的最佳姿势
    如果你github提交代码,报错remote: Support for password authentication was removed on August 13, 2021.
    js将连接符命名和驼峰命名互转
    滚动条常用样式
    计算该浏览器中滚动条的默认宽度
    解决webpack-dev-server启动后localhost:port可以访问,IP:port不能访问的问题
    获取滚动条宽度的方法
    mysql中的数据类型
    数据库和表的操作
    mysql插入,删除,修改记录
  • 原文地址:https://www.cnblogs.com/railgunman/p/8627572.html
Copyright © 2011-2022 走看看