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

  • 相关阅读:
    [LeetCode] 117. Populating Next Right Pointers in Each Node II
    [LeetCode] 229. Majority Element II
    [LeetCode] 876. Middle of the Linked List
    HttpClient 使用案例
    github 拷贝项目到本地
    tomcat下文件路径
    同一个tomcat 两个项目 互相访问接口方法
    Mysq 列中存储json格式根据key取value
    mysql 函数和存储过程的区别
    mysql触发器
  • 原文地址:https://www.cnblogs.com/feng801/p/1270271.html
Copyright © 2020-2023  润新知