Mega Code Archive

 
Categories / Delphi / Ide Indy
 

How to Declare a Constant Record in Delphi

Title: How to Declare a Constant Record in Delphi 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;