|The SDL Component Suite is an industry leading collection of components supporting scientific and engineering computing. Please visit the SDL Web site for more information....|
|Home BasePack DStruct Class TStringArray How to use TStringArray|
|See also: Data structure of TStringArray|
In order to use TStringArray you first have to put one or more instances from the component palette to the form. Alternatively you can create one or several instances of TStringArray manually (see example code below). Thereafter the string array is empty and may be filled with strings by assigning them to the array property Elem. The rows of the string array can be sorted according to the strings of a certain column. Each row has a row attribute, which is a byte value and can be accessed by the property RowAttrib.The row attribute can be freely utilized by the user for storing user-defined attributes. When an instance of TStringArray is not needed any longer, you should call the method Free to deallocate the reserved memory. The property AllocRowsBy determines how many extra space is allocated in memory when changing the dimension of the StringArray. AllocRowsBy should be set to higher values for fast resizing operations. However, memory efficiency is best when AllocBy is set to 1.
Note: TStringArray can handle strings up to 255 characters. Any longer strings will be truncated to the first 255 characters.
Here is a short sample code how to use the class TStringArray. After the array MyArray of size 100 by 3000 is created, the elements [23,1853] and [100,3000] are filled with some text. Note that the property Elem is the default property and may be omitted (as in the first assignment). Finally the array is removed from the memory:
MyArray := TStringArray.Create (nil); MyArray.Resize(100,3000); MyArray [23, 1853] := 'this string is stored in element [23,1853]'; MyArray.Elem [MyArray.NrOfColumns,MyArray.NrOfRows] := 'very last cell'; MyArray.Free;