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 ;.
     

  • 相关阅读:
    最长公共前缀
    罗马数字转整数
    回文数
    整数反转
    Linux内核设计与实现——进程管理
    技术派-常用的一些VS相关的宏名
    假如面试3道小学数学题,你可否会?
    技术派-不用sqrt手工计算平方根
    观察者-学历差距造成的差距有多大
    10G文件如何对里面单词出现排序
  • 原文地址:https://www.cnblogs.com/feng801/p/1270271.html
Copyright © 2011-2022 走看看