Make your own free website on Tripod.com

TContainer

libcont.gif (986 bytes)TContainer component should be used to store data in memory, and provides access to disk files - ASCII texts and binary streams. TContainer allocates internal TList object to keep pointers to data elements array. Data elements are descendants of abstract TData class. Currently 3 useful data classes are predefined in Data.pas unit: TFunction, TRealData and TStringData. TContainer (and other components) is polymorphic: it may contain any TData descendant class and even items of different classes simultaneously.

See also IDMContainer interface for additional information.

public members

Read/only property r/o property Items: TList

Keeps pointers to data elements. You should use TContainer.Clear() method instead of TList.Clear() to deallocate items data. Use other TList methods and properties to access, add or delete elements. Use InitItem method to create data elements and Free procedure to destroy them.

Property property Modified: boolean

This property used to track data modifications. When you change this property (directly or indirectly), OnChanged event is fired.

Property property DataClass: TDataClass

This property affect on class type of data elements created by InitItem method. You may use your own data classes derived from standard ones.

Method procedure ShowProgress(P: integer); virtual

This method used to display progress of time-consuming operations like disk access or bulk data modification. Note that this method may be called by TWorksheet component. By default it fires OnProgress event.

Method function InitItem: TData; virtual

Creates data element. Uses OnInitItem event handler or DataClass property.

Method procedure Clear

Clear Items object and free all data elements. In addition, set Modified property to true. Use this method instead of TList's one.

Method procedure LoadFromFile

Method procedure SaveToFile(Backup: boolean)

Text file support routines. Text-type file must contain values separated by commas, tabstops or spaces. Decimal point character always assumed to be point (.). Both use FileName property, Modified property automatically cleared. If Backup=true, backup copy will be created. Unlike other methods, LoadFromFile() display progress as number of lines.

Method procedure LoadFromStream(S: TStream)

Method procedure SaveToStream(S: TStream)

Stream support routines. Also clear Modified property. DataType remembered in the stream, InitItem used to create data elements.

Method procedure Sort(BegLine,EndLine: integer; Descend: boolean)

Sorts selected items range (from BegLine to EndLine) with fast recursive QuickSort algorithm. Descend parameter defines sort order.

Method procedure Assign(Source: TPersistent); override

Standard VCL method allows you to copy data from another container or TStrings object. Modified property set to true.

Method function Calibrate(R:TReal; Index,Key: integer): TReal

This method performs table calibration. Works only with TRealData items. Index is position of returned value, Key used to seek between data items.

published members

Property property FileName: string

Disk file name hold by container. If AutoLoad property is true, file will be automatically loaded when you assign value to this property.

Property property DataType: TDataType

Allows you to set the type of data elements at design-time. If you set this property to dtCustom you must create OnInitItem event handler or set DataClass property.

Property property UpdateCaption: boolean

If this property is true, container will update owner's caption every time when you change FileName property.

Property property AutoLoad: boolean

If this property is true, file will be automatically loaded when you assign new value to FileName property. This feature may be especially useful to load data into container at design-time.

Property property OnInitItem: TInitItemEvent

Define this handler to create data elements of your own type. This handler also useful to perform additional initialization for standard data elements.

Property property OnProgress: TProgressEvent

Use this handler to display progress of time-consuming operations. See ShowProgress() method above.

Property property OnChanged: TNotifyEvent

Called when data in container are changed in some way. See Modified property above.

Property property OnCompare: TCompareEvent

Write this handler if you want to sort data elements with Sort() method. Note that this handler must always return correct result!