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 8079295
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T16:03:41+00:00 2026-06-05T16:03:41+00:00

What difference does it make when I use a const parameter in a procedure?

  • 0

What difference does it make when I use a const parameter in a procedure?

Take the following procedure for example:

procedure DoSomething(Sender: TObject; const Text: String; var Reply: String);
begin
  //Text is read-only and Reply will be passed back wherever DoSomething() was called
  Reply:= Text;
end;

The parameter Text: String is prefixed with const so that (as far as I know), a copy of the value is made and used – and is read-only. What I was wondering is how is does this affect the application any differently than if I didn’t put const there? Perhaps a performance trick?

  • 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-05T16:03:43+00:00Added an answer on June 5, 2026 at 4:03 pm

    Looking at the documentation states:

    “Using const allows the compiler to optimize code for structured – and string-type parameters. It also provides a safeguard against unintentionally passing a parameter by reference to another routine.”

    In case of a string for example the optimization means there is no additional refcounting when passing as const. Also passing as const does not mean it’s a copy. Often it internally passes as reference because the compiler ensures no write access to it.

    Some very interesting articles to completly understand what’s going on under the hood:

    http://delphitools.info/2010/07/28/all-hail-the-const-parameters

    http://vcldeveloper.com/articles/different-function-parameter-modifiers-in-delphi

    Edit:

    A simple example to show that const may result in pass by reference internally:

    program Project1;
    
    {$APPTYPE CONSOLE}
    
    type
      PMyRecord = ^TMyRecord;
      TMyRecord = record
        Value1: Cardinal;
        Value2: Cardinal;
      end;
    
    procedure PassAsConst(const r: TMyRecord);
    begin
      PMyRecord(@r).Value1 := 3333;
      PMyRecord(@r).Value2 := 4444;
    end;
    
    procedure PassByVal(r: TMyRecord);
    begin
      PMyRecord(@r).Value1 := 3333;
      PMyRecord(@r).Value2 := 4444;
    end;
    
    var
      r: TMyRecord;
    begin
      r.Value1 := 1111;
      r.Value2 := 2222;
      PassByVal(r);
      Writeln(r.Value1);
      Writeln(r.Value2);
    
      PassAsConst(r);
      Writeln(r.Value1);
      Writeln(r.Value2);
    
      Readln;
    end.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What difference does it make when I use float and decimal data types in
Does it make any difference if I use e.g. short or char type of
public or protected methods does not make any difference for a private nested class
When using on_start() does it make any difference to do, // ENABLE GZIP COMPRESSION
Does the length of the CommandText of an SqlCommand make a difference? I'm not
Does the order and/or size of shader in/out variables make any difference in memory
When performing many disk operations, does multithreading help, hinder, or make no difference? For
I have a Java EE web application that does not make use of EJBs.
Does it make any difference to prefer varchar2 over date data type when building
In a SQL Server where clause does it make any difference whether you code

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.