zoukankan      html  css  js  c++  java
  • 引用传参(摘引自Delphi Basic)

         
    Passing by reference means that the subroutine actually refers to the passed variable rather than its value. Any changes to the value will affect the caller variable. We declare a variable to be passed by reference with the var prefix. Rewriting the above code to use by reference changes matters:
     
     procedure DoIt(Var A : Integer);
     begin
       A := A * 2;
       ShowMessageFmt('A in the procedure  = %d',[A]);
     end;
     
     procedure TForm1.FormCreate(Sender: TObject);
     var
       A : Integer;
     begin
       A := 22;
       ShowMessageFmt('A in program before call = %d',[A]);
       // Call the procedure
       DoIt(A);
       ShowMessageFmt('A in program now = %d',[A]);
     end;

     A in program before call = 22
     A in the procedure = 44
     A in program now = 44

    Now the caller A variable is updated by the procedure.
     
    This is a very useful way of returning data from a procedure, as used by, for example, the Delphi Insert routine. It also allows us to return more than one value from a subroutine.
  • 相关阅读:
    1289 大鱼吃小鱼
    install ios开发环境
    Xcode_5
    嵌入式学习_AD学习篇
    课务IOS概述_1
    动态规划入门(2):01背包问题
    Python记之薄暮笔记
    线段树进阶:权值线段树
    动态规划入门(1):最长递增子序列
    python记之Hello world!
  • 原文地址:https://www.cnblogs.com/feng801/p/1270269.html
Copyright © 2011-2022 走看看