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

  • 相关阅读:
    VC++ MFC工程中中如何将一个工程的资源(如对话框)复制到另外一个工程
    VS调试_ASSERTE(_BLOCK_TYPE_IS_VALID(pHead->nBlockUse));崩溃原因及解决方法
    使用libcurl下载文件小例
    [工具] 程序员必须软件
    [Linux] Linux软连接和硬链接
    [Android Pro] Android的Animation之LayoutAnimation使用方法
    [Java基础] java的守护线程与非守护线程
    [Linux] 守护进程和守护线程
    [Linux] linux文件系统学习
    [Java基础] Java线程复习笔记
  • 原文地址:https://www.cnblogs.com/railgunman/p/8627572.html
Copyright © 2011-2022 走看看