zoukankan      html  css  js  c++  java
  • Output only parameters(摘引自Delphi Basic)

    We can go further, and define parameters that we can update, but which are there for update only - output from our subroutine. They should not be read by the subroutine, the caller not responsible for any starting value they might contain.
     
     procedure DoIt(Out A : Integer);
     begin
       A := 123;
       ShowMessageFmt('A in the procedure  = %d',[A]);
     end;
     
     procedure TForm1.FormCreate(Sender: TObject);
     var
       A : Integer;
     begin
       ShowMessage('A before the call is unknown');
       // Call the procedure
       DoIt(A);
       ShowMessageFmt('A in program now = %d',[A]);
     end;

     A before the call is unknown
     A in the procedure = 123
     A in program now = 123


    Constant value parameters
    For code clarity, and performance, it is often wise to declare arguments that are only ever read by a subroutine as constants. This is done with the const prefix. It can be used even when a non-constant parameter is passed. It simply means that the parameter is only ever read by the subroutine.
     
     procedure DoIt(Const A : Integer; Out B : Integer);
     begin
       B := A * 2;
     end;
     
     procedure TForm1.FormCreate(Sender: TObject);
     var
       A, B : Integer;
     begin
       A := 22;
       // Call the procedure
       DoIt(A, B);
       ShowMessageFmt('B has been set to = %d',[B]);
     end;

     B has been set to 44

    Notice that when defining two argument types, the arguments are separated with a ;.
     

  • 相关阅读:
    Redhat MysqlReport安装配置详解
    asp.net中服务器端控件和客户端控件的交互问题
    关于弹出对话框返回值的分析
    关于父子窗口的参数传递(引用的高手的)
    呵呵!刚刚申请!
    Loadrunner教程
    性能测试常见用语
    如何删除电脑垃圾文件
    内连接和外连接
    酒桌上的规矩
  • 原文地址:https://www.cnblogs.com/feng801/p/1270271.html
Copyright © 2011-2022 走看看