Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set default value to record in delphi

I am using RAD XE7. In my Delphi application I want to set default values for fields of Records.

I tried following code, but it does not compile, I know it is wrong. I there any another way?

 TDtcData = record
    TableFormat     : TExtTableFormat = fmNoExtendedData;
    DTC             : integer = 0;
    Description     : string = 'Dummy';
    Status          : TDtcStatus;    
    OccurenceCnt    : integer =20;
    FirstDTCSnapShot: integer;
    LastDTCSnapShot: integer;
  end; 
like image 610
Ankush Avatar asked Dec 14 '22 20:12

Ankush


1 Answers

If you want to define a partially initialized record, just declare a constant record, but omit those parameters not needing default values:

Type
  TDtcData = record
  TableFormat     : TExtTableFormat;
  DTC             : integer;
  Description     : string;
  Status          : TDtcStatus;
  OccurenceCnt    : integer;
  FirstDTCSnapShot: integer;
  LastDTCSnapShot: integer;
end;

Const
  cDefaultDtcData : TDtcData = 
    (TableFormat : fmNoExtendedData; 
     DTC : 0; 
     Description : 'Dummy'; 
     OccurenceCnt : 20);

var
  someDtcData : TDtcData;
begin
  ...
  someDtcData := cDefaultDtcData;
  ...
end;
like image 61
LU RD Avatar answered Dec 28 '22 05:12

LU RD