[fpc-pascal] Pre-initialising a TStringList

Juha Manninen juha.manninen62 at gmail.com
Sun Feb 6 16:04:19 CET 2011


Sven Barth kirjoitti sunnuntai 06 helmikuu 2011 16:24:49:
> FPreInitialisedSList.Text := StringsToUse;
> 
> Note: You can also define StringsToUse as a typeless constant, e.g.:
> 
> const StringsToUse = 'Line 1' + LineEnding +
> 			'Line 2' + LineEnding +
> 			// + ...
> 			'Line n';

The most obvious solution is the best this time.

List.Add('Line 1');
List.Add('Line 2');
...
List.Add('Line n');

Setting the Text property (or calling the SetText method) parses the text and 
splits it by NewLine chars. It makes no sense because you have concatenated 
the strings with NewLines.
Method Add does not need to parse anything.

None of these solutions is "preinitialised", compile time solution.
You can only initialize a const static arrays at compile time.

Juha



More information about the fpc-pascal mailing list