Initializing arrays

Top  Previous  Next

What is translated > Initializing arrays

 

Array's are initialized very simply in Delphi. The initialization of an array of TStyleRecord's:

 

TStyleRecord = record

  Name    : string;

  Color   : TColor;

  Style   : TFontStyles;

end;

 

could look like: 

 

DefaultStyles : TStylesArray = (

 (Name : 'tnone';    Color : clBlack;  Style :  []),

 (Name : 'tstring';  Color : clMaroon; Style :  []),

 (Name : 'tcomment'; Color : clNavy;   Style :  [fsItalic])

);

 

This was translated in the earlier versions of Delphi2Cpp as:

 

TStylesArray DefaultStyles = { 

 { "tnone" /*Name*/, clBlack /*Color*/, arrays__0 /*Style*/ },

 { "tstring" /*Name*/, clMaroon /*Color*/, arrays__1 /*Style*/ },

 { "tcomment" /*Name*/, clNavy /*Color*/, arrays__2 /*Style*/ } 

};

 

It is a problem however,  that such initializations are only possible, if the elements are built in types of C. Such initializations of elements of the type TFontStyle aren't permitted. Beginning with version 1.2.4., Delphi2Cpp therefore generates initialization functions which are called within the initialization routine of the corresponding unit.

 

void DefaultStylesInit( )

{

  DefaultStyles[0].Name = "tnone";

  DefaultStyles[0].Color = clBlack;

  DefaultStyles[0].Style = arrays__0;

  DefaultStyles[1].Name = "tstring";

  DefaultStyles[1].Color = clMaroon;

  DefaultStyles[1].Style = arrays__1;

  DefaultStyles[2].Name = "tcomment";

  DefaultStyles[2].Color = clNavy;

  DefaultStyles[2].Style = arrays__2;

}

 

void DefaultStylesInit( )

{

  DefaultStylesInit0( );

  DefaultStylesInit1( );

  DefaultStylesInit2( );

}

 

 



This page belongs to the Delphi2Cpp Documentation

Delphi2Cpp home  Content