Output only parameters (extracted from Delphi basic)

Source: Internet
Author: User
we can go further, and define parameters that we can update, but which are there for update only-output from our subroutine. they shocould not be read by the subroutine, the caller not responsible for any starting value they might contain.
procedure doit (out a: integer);
begin
: = 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 withConstPrefix. 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;.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.