[fpc-pascal] Pre-initialising a TStringList

Mark Morgan Lloyd markMLl.fpc-pascal at telemetry.co.uk
Sun Feb 6 16:50:05 CET 2011

Juha Manninen wrote:
> 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.

Thanks for that Juha (et al.). I wanted to make sure that I wasn't 
missing something that I really should have known.

Is it possible to set up the text as an attribute (I'm avoiding the word 
property here for obvious reasons) of the entire class rather than of an 

Should I be looking at resources here and if so could they be kept in 
the main source file?

This is for a highly-experimental SNMP MIB to Pascal translator that I'm 
tinkering with so- as an example- there will be a single class 
describing an HP Ethernet switch which may be instantiated but will have 
common descriptive text.

Mark Morgan Lloyd
markMLl .AT. telemetry.co .DOT. uk

[Opinions above are the author's, not those of his employers or colleagues]

More information about the fpc-pascal mailing list