Delphi Programming

  1. Home
  2. Computing & Technology
  3. Delphi Programming

How to Declare a Constant Record in Delphi

By Zarko Gajic, About.com

Record data types in Delphi represent a mixed set of elements. Each element is called a field; the declaration of a record type specifies a name and type for each field.

Constant Record

To create a constant or "read-only" record, use the next "initialization":
//record declaration
type
  TDeveloper = record
    Language : string;
    Experience : integer;
    Salary : Currency;
  end;

...
//"DelphiDeveloper" TDeveloper constant
const
  DelphiDeveloper : TDeveloper =
      (
        Language : 'Delphi';
        Experience : 15;
        Salary : 200000
      ) ;
Note that if you try to assign a different value to any of the fields of the constant "DelphiDeveloper", you will get a compile time exception:
begin
  //compile time exception:
  "Left side cannot be assigned to"

  DelphiDeveloper.Language := 'C#'
end;

Delphi tips navigator:
» How to Override Delphi Form's Restore Operation?
« How to Store a String value to a Tag Property of a Delphi control

More Delphi Programming Quick Tips
Zarko Gajic
Guide since 1998

Zarko Gajic
Delphi Programming Guide

Explore Delphi Programming

About.com Special Features

Delphi Programming

  1. Home
  2. Computing & Technology
  3. Delphi Programming
  4. Coding Delphi Applications
  5. Delphi Tips and Tricks
  6. Delphi 2007 Tips
  7. How to Declare a Constant Record in Delphi

©2009 About.com, a part of The New York Times Company.

All rights reserved.