Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8327103
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T00:59:34+00:00 2026-06-09T00:59:34+00:00

I’ve noticed that different codes declare parameters in a different way to how I

  • 0

I’ve noticed that different codes declare parameters in a different way to how I do, and I wonder if there is a specific reason to do so, or whether it is a preference.

Say I wrote this function (just an example with different parameters)

function DoSomething(AHeight, AWidth: Integer; R: TRect): Boolean
begin
  //
end;

How is this any different then if it was declared like so:

function DoSomething(var AHeight, AWidth: Integer; const R: TRect): Boolean
begin
  //
end;

I know a variable is read/writeable and a constant is read-only, but how does declaring parameters this way make a difference?

To me both functions are looking for the calling code to provide a Height, Width and Rect, but the 2nd function makes it look like we are declaring new variables.

I have a feeling this is going to be such a straight forward answer I feel silly for asking but I must know what the difference is, if any?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T00:59:36+00:00Added an answer on June 9, 2026 at 12:59 am

    The documentation explains this very clearly:

    Most parameters are either value parameters (the default) or variable
    (var) parameters. Value parameters are passed by value, while variable
    parameters are passed by reference. To see what this means, consider
    the following functions:

    function DoubleByValue(X: Integer): Integer;   // X is a value parameter
    begin
      X := X * 2;
      Result := X;
    end;
    
    function DoubleByRef(var X: Integer): Integer;  // X is a variable parameter
    begin
      X := X * 2;
      Result := X;
    end;
    

    These functions return the same result, but only the second one –
    DoubleByRef can change the value of a variable passed to it. Suppose
    we call the functions like this:

    var
      I, J, V, W: Integer;
    begin
      I := 4;
      V := 4;
      J := DoubleByValue(I);   // J = 8, I = 4
      W := DoubleByRef(V);     // W = 8, V = 8
    end;
    

    After this code executes, the variable I, which was passed to
    DoubleByValue, has the same value we initially assigned to it. But the
    variable V, which was passed to DoubleByRef, has a different value.

    A value parameter acts like a local variable that gets initialized to
    the value passed in the procedure or function call. If you pass a
    variable as a value parameter, the procedure or function creates a
    copy of it; changes made to the copy have no effect on the original
    variable and are lost when program execution returns to the caller.

    A variable parameter, on the other hand, acts like a pointer rather
    than a copy. Changes made to the parameter within the body of a
    function or procedure persist after program execution returns to the
    caller and the parameter name itself has gone out of scope.

    Even if
    the same variable is passed in two or more var parameters, no copies
    are made. This is illustrated in the following example:

    procedure AddOne(var X, Y: Integer);
    begin
      X := X + 1;
      Y := Y + 1;
    end;
    
    var I: Integer;
    begin
      I := 1;
      AddOne(I, I);
    end;
    

    After this code executes, the value of I is 3.


    I recommend that you add a link to the Delphi Language guide to your browser’s bookmarks.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I know there's a lot of other questions out there that deal with this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I am doing a simple coin flipping experiment for class that involves flipping a
I need a function that will clean a strings' special characters. I do NOT

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.