[fpc-pascal] Pre-initialising a TStringList

Howard Page-Clark hdpc at talktalk.net
Sun Feb 6 15:19:14 CET 2011


On 06/2/11 1:55, Mark Morgan Lloyd wrote:
> Given one or more lines of text which are known at compilation time, and
> without the requirement to internationalize (these are, by RFC, US
> ASCII), what is the best way to get them into a TStringList?

Perhaps there are better ways than the straightforward way?

const StringsToUse: string = 'Line 1'+LineEnding+
                              'Line 2'+LineEnding+
                              // + ...
                              'Line n';

var  FPreInitialisedSList: TStringList;

begin
   FPreInitialisedSList := TStringList.Create;
   FPreInitialisedSList.SetText(PChar(StringsToUse));

   // ...

   FPreInitialisedSList.Free;

H




More information about the fpc-pascal mailing list