1. Technology

Advanced Record Structure Type in Turbo Delphi and Delphi 2006

Records Almost Like Classes


Advanced Record Type in Turbo Delphi / Delphi 2006

Advanced Record Type in Turbo Delphi / Delphi 2006

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.

Records are commonly used in Microsoft Windows API calls, where they are referred to as "structures".

"Understanding and Using Record Data Types in Delphi" describes what records are, how to declare and use records. What's more, if you know that you will never need to use all of the fields in a single record instance, you can use variant records.

Smarter Records in Turbo Delphi / Delphi 2006

Records in Turbo Delphi (Delphi 2006) are even more powerful!

How about having a record constructor where you can initialize record field values? How about having properties in records? Cool, ha :)

Here's a list of the new record features in Turbo Delphi (Delphi 2006)

  • Records can have constructor, with at least one parameter.
  • Records support properties and static methods.
  • Records support operator overloading.
  • Records can have methods (functions, procedures).
  • Records do NOT support virtual methods ("virtual", "dynamic", and "message")
  • Records do NOT support destructors.
Note: records are value types. Records are are copied on assignment, passed by value.

Here's an example of the new, advanced records in Delphi 2006:

   TTurboRecord = record
   strict private
     fNameValue : integer;
     function GetName: string;
     NamePrefix : string;
     constructor Create(const initNameValue : integer) ;
     property Name : string read GetName;
 constructor TTurboRecord.Create(const initNameValue : integer) ;
   fNameValue := initNameValue;
   NamePrefix := '"record constructor"';
 function TTurboRecord.GetName: string;
   Inc(fNameValue) ;
   result := Format('%s %d',[NamePrefix, fNameValue]) ;
Drop a TMemo control on a form and try the following code:
   turboRecord : TTurboRecord;
   anotherTurboRecord : TTurboRecord;
   //no Constructor needed - fNameValue = 0 by default
   turboRecord.NamePrefix := 'turboRecord';
   Memo1.Lines.Add(turboRecord.Name) ;
   Memo1.Lines.Add(turboRecord.Name) ;
   //constructor used
   turboRecord := TTurboRecord.Create(2006) ;
   Memo1.Lines.Add(turboRecord.Name) ;
   Memo1.Lines.Add(turboRecord.Name) ;
   anotherTurboRecord := turboRecord;
   anotherTurboRecord.NamePrefix := 'anotherTurboRecord';
   Memo1.Lines.Add(anotherTurboRecord.Name) ;
   Memo1.Lines.Add(anotherTurboRecord.Name) ;
   Memo1.Lines.Add(turboRecord.Name) ;
   Memo1.Lines.Add(turboRecord.Name) ;
   //NO need to FREE record types
Delphi tips navigator:
» Understanding and (Not) Using the Goto Delphi Statement
« Allow Only One Application Execution per Windows Session

©2014 About.com. All rights reserved.