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

原文地址:https://www.cnblogs.com/feng801/p/1270271.html