TdxCustomMemData Class
The base class for the TdxMemData component.
Declaration
TdxCustomMemData = class(
TDataSet
)
Remarks
The TdxCustomMemData
class implements a memory-based dataset component designed as a temporary storage for data-aware controls.
Main API Members
The list below outlines key members of the TdxCustomMemData
class. These members allow you to populate a memory-based dataset and manage data at runtime.
Data Binding
- Active | Close | Open
Allow you to open and close the memory-based dataset. When the dataset is closed, it cannot exchange data with data-aware controls.
Note
You need to close the dataset when you change the field structure or data binding settings (DataSource, for example).
- DataSource
- Allows you to associate the memory-based dataset with a data source component.
Field Structure Management
- CreateFieldsFromBinaryFile | CreateFieldsFromDataSet | CreateFieldsFromStream
- Creates dataset fields from the specified source.
- CopyFromDataSet
- Copies the data field structure and data from another data source.
Data Management
- Append | Insert
- Create a new empty record.
- AppendRecord | InsertRecord
- Create a new populated record.
- Data
- Provides access to the collection of dataset fields stored in memory.
- Delete
- Deletes the active record and moves the current position to the next record.
- GetValueCount
- Returns the number of records that contain the specified value.
- IsEmpty
- Identifies if the dataset contains records.
- MoveCurRecordTo
- Moves the current record to the specified position in the dataset.
- ReadOnly
- Allows you to protect data from changes.
- RecordCount
- Returns the number of stored dataset records.
Data Shaping
- FilterList | ProgrammedFilter | Filtered | OnFilterRecord
- Allow you to filter data.
- SortedFields | SortOptions
- Allow you to sort data against one or more dataset fields.
Import and Export
- DelimiterChar
- Specifies the column delimiter character for text-based files that store exported data.
- LoadFromDataSet | LoadFromBinaryFile | LoadFromStream | LoadFromStrings | LoadFromTextFile
- Populate the dataset from a source dataset, file, string array, or stream.
- SaveToBinaryFile | SaveToStream | SaveToStrings | SaveToTextFile
- Save data to a file or stream.
Record Navigation
- Bof | Eof
- Identify if the current position in the dataset is at the first or last record.
- First | Last | Next | Prior
- Navigate between dataset records.
General-Purpose API Members
- DisableControls | EnableControls
- Allow you to avoid excessive redraw operations in associated data-aware controls during batch dataset changes.
- Persistent
- Provides access to the component’s DFM-related content storage settings.
Code Examples
Create Fields and Records
The following code example creates three dataset fields and two records in a TdxMemData component, and displays data in a bound data-aware grid Table View:
uses
dxmdaset, cxGrid, cxGridDBTableView;
// ...
procedure TMyForm.CreateField(AMemData: TdxMemData; AFieldName: string; AFieldType: TFieldType);
var
AFieldDef: TFieldDef;
begin
if ((AMemData = nil) or (AFieldName = '')) then Exit;
AFieldDef := AMemData.FieldDefs.AddFieldDef;
AFieldDef.Name := AFieldName;
AFieldDef.DataType := AFieldType;
AFieldDef.CreateField(AMemData);
end;
procedure TMyForm.FormCreate(Sender: TObject);
begin
dxMemData1.DisableControls;
try
if dxMemData1.Active then
dxMemData1.Close;
// Create three fields in the memory-based dataset
CreateField(dxMemData1, 'ID', ftInteger);
CreateField(dxMemData1, 'FirstName', ftString);
CreateField(dxMemData1, 'LastName', ftString);
// Create two records and populate corresponding data cells
dxMemData1.Open;
dxMemData1.Append;
dxMemData1.FieldByName('ID').AsInteger := 0;
dxMemData1.FieldByName('FirstName').AsString := 'James';
dxMemData1.FieldByName('LastName').AsString := 'Packard';
dxMemData1.Append;
dxMemData1.FieldByName('ID').AsInteger := 1;
dxMemData1.FieldByName('FirstName').AsString := 'Hannah';
dxMemData1.FieldByName('LastName').AsString := 'Brooklyn';
dxMemData1.Post;
finally
dxMemData1.EnableControls;
end;
cxGrid1DBTableView1.DataController.CreateAllItems();
end;
Delete All Records
To delete all records, you can reopen the memory-based dataset. Make sure that the dataset’s Persistent.Option property is set to poNone to avoid an automatic data reload operation from a DFM file when the dataset becomes active.
The following code example deletes all records stored in a memory-based dataset:
if dxMemData1.Persistent.Option = poActive then
dxMemData1.Persistent.Option := poNone;
dxMemData1.Close;
dxMemData1.Open;
Terminal TdxCustomMemData Class Descendants
Do not use the TdxCustomMemData
class directly. Use the TdxMemData component instead.