TStrings is one of the most useful and flexible non-visual objects in Delphi. To see how flexible it is, all you have to do is take a look at the following code samples demonstrating different ways of saving and retrieving string values from it.
Example 1:
var sl : TStrings; begin sl := TStringList.Create;
// add string values... sl.Add( 'Delphi' ); sl.Add( '2.01' );
// get string value using its index // sl.Strings( 0 ) will return // 'Delphi' MessageDlg( sl.Strings[ 0 ], mtInformation, [mbOk], 0 );
sl.Free; end; |
Example 2:
var sl : TStrings; begin sl := TStringList.Create;
// set string values... sl.Values[ 'Program' ] := 'Delphi'; sl.Values[ 'Version' ] := '2.01';
// get string values... // sl.Values[ 'Program' ] will return // 'Delphi' MessageDlg( sl.Values[ 'Program' ], mtInformation, [mbOk], 0 );
sl.Free; end; |
Example 3:
var
sl : TStrings;
begin
sl := TStringList.Create;
// set string values...
sl.Add( 'Program=Delphi' );
sl.Add( 'Version=2.01' );
// get string values...
// sl.Values[ 'Program' ] will return
// 'Delphi'
MessageDlg(
sl.Values[ 'Program' ],
mtInformation, [mbOk], 0 );
sl.Free;
end;
Source : http://www.chami.com/tips/delphi/010497D.html
0 comments:
Post a Comment