Table of Contents

Dataset

TTMSFNCDataSet is an abstract dataset that integrates with the standard Delphi TDataSet infrastructure. It can load data from any structure that implements ITMSFNCDataObject, including TList, TDictionary, TStringList, and custom objects.

Key class: TTMSFNCDataSet

Use TTMSFNCDataLinkCSV or TTMSFNCDataLinkJSON to load CSV or JSON data, or implement ITMSFNCDataObject for custom data structures.

TTMSFNCDataSet1

Linking to a Data Structure

Set DataLink at design time (for TComponent descendants) or DataObject at runtime:

TMSFNCDataSet1.DataLink := TTMSFNCDataLinkJSON1;
// or
TMSFNCDataSet1.DataObject := MyCustomDataLink;
TMSFNCDataSet1.Active := True;

Filtering

Filter Property

Use SQL-style filter expressions with | for OR and & for AND:

TMSFNCDataSet1.Filtered := False;
TMSFNCDataSet1.Filter := 'Country = "Belgium" | Country = "Germany"';
TMSFNCDataSet1.Filtered := True;

OnFilterRecord Event

procedure TForm1.TMSFNCDataSet1FilterRecord(DataSet: TDataSet; var Accept: Boolean);
begin
  Accept := DataSet.FieldByName('Name').AsString.Contains('John');
end;

TMSFNCDataSet1.OnFilterRecord := TMSFNCDataSet1FilterRecord;
TMSFNCDataSet1.Filtered := True;

Sorting

TMSFNCDataSet1.SortBy('Age');   // sort ascending by Age
TMSFNCDataSet1.Unsort;           // revert to original order

Implement ITMSFNCDataObject to connect any data structure:

Method Description
Activate(AValue) Called when the dataset's Active property changes
AddRecord(ARecord) Add a new record
CompareRecords(AField, ARecord1, ARecord2) Compare two records for sorting
CreateDefaultRecord Return an empty record (not nil)
DeleteRecord(ARecord) Delete a record by index
GetRecord(AIndex) Return the record at the given index
GetRecordCount Return total record count
GetRecordIndex(ARecord) Return the index of a matching record
GetRecordValue(ARecord, AField, AFieldType) Return a field value from a record
InitializeFieldDefs(AFieldDefs) Initialize field definitions
InsertRecord(AIndex, ARecord) Insert a record at an index
SetRecordValue(ARecordIndex, AField, AValue) Set a field value
SetNotification(ANotifyObject) Store the dataset notification reference for push updates

To push updates back to the dataset, call methods on the stored ITMSFNCDataObjectNotification:

procedure TMyDataLink.SetNotification(ANotifyObject: ITMSFNCDataObjectNotification);
begin
  FNotifyObject := ANotifyObject;
end;

procedure TMyDataLink.DataChanged;
begin
  FNotifyObject.DataRefresh;
end;
Tip

For a worked example, see the TTMSFNCDataSet/CustomDataLink demo included with TMS FNC Core.

See Also