Delphi function Parameters Pass default parameters (value values), VAR (pass-through), out (output), const (constant) class four

Source: Internet
Author: User

Delphi parameters can be divided into: default parameters (Value), VAR (address), out (output), const (constant) four class

You can compare the knowledge of C + + with analogy learning.

1. The default parameter is the pass value, will not be changed, example

function Myfun (x:integer): Integer;begin    Inc (x);    Result: = X;end;

The 2.var parameter is the address that will be changed, example

function Myfunvar (var x:integer): Integer;begin    Inc (x);    Result: = X;end;

3.out parameters are supported for COM, and the result of Var is the same, generally we do not need

function myfunout (out X:integer): Integer;begin    Inc (x);    Result: = X;end;

4.const parameters are absolutely not assignable, this is the way the compiler optimizes, as much as possible

function Myfunconst (const X:integer): Integer;begin    Inc (x);    This is an error because the parameter with the const prefix is the Result that cannot be modified    : = X;end;

  

Here are the tests that call these functions

Procedure Tform1.button1click (sender:tobject); var   a:integer;begin    A: = 5;    Myfun (a);    ShowMessage (IntToStr (a));    6        A: = 6;    Myfunvar (a);    ShowMessage (IntToStr (a));    7    A: = 6;    Myfunout (a);    ShowMessage (IntToStr (a));    7    A: = 6;    Myfunconst (a);    ShowMessage (IntToStr (a));    6, because in the myfunconst is not the const parameter can be modified end;

  

Delphi function Parameters Pass default parameters (value values), VAR (pass-through), out (output), const (constant) class four

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.