Skip to content

TMemDataset

Base class for records-based data-access.

Declaration

Source position: memds.pp line 58

type

  TMemDataset = class(TDataSet)
  public
    constructor Create;
    destructor Destroy;
    function BookmarkValid : Boolean;
    function CompareBookmarks : LongInt;
    function CreateBlobStream : TStream;
    function Locate : Boolean;
    function Lookup : Variant;
    procedure CreateTable;
    function DataSize : Integer;
    procedure Clear(ClearDefs: Boolean);
    procedure Clear;
    procedure SaveToFile(const AFileName: string);
    procedure SaveToFile(const AFileName: string; SaveData: Boolean);
    procedure SaveToStream(F: TStream);
    procedure SaveToStream(F: TStream; SaveData: Boolean);
    procedure LoadFromStream;
    procedure LoadFromFile;
    procedure CopyFromDataset(DataSet: TDataSet);
    procedure CopyFromDataset(DataSet: TDataSet; CopyData: Boolean);
    property FileModified: Boolean; {r}
    property Filter;
  published
    property FileName: string; {rw}
    property Filtered;
    property Active;
    property FieldDefs;
    property BeforeOpen;
    property AfterOpen;
    property BeforeClose;
    property AfterClose;
    property BeforeInsert;
    property AfterInsert;
    property BeforeEdit;
    property AfterEdit;
    property BeforePost;
    property AfterPost;
    property BeforeCancel;
    property AfterCancel;
    property BeforeDelete;
    property AfterDelete;
    property BeforeScroll;
    property AfterScroll;
    property OnDeleteError;
    property OnEditError;
    property OnNewRecord;
    property OnPostError;
    property OnFilterRecord;
  end;

Description

TMemDataset is a TDataset descendant which implements an in-memory dataset. TMemDataset is a performant, single user dataset for non-mission critical use cases that do not require transactions. All record and field processing is done in memory; no data is read from or written to disk unless explicitly requested.

TMemDataset implements common facilities defined in the TDataset ancestor class. This includes using the FieldDefs property to define the structure for the dataset. Most (but not all) field types are supported in TMemDataset, including:

  • ftString
  • ftGuid
  • ftFixedChar
  • ftBoolean
  • ftCurrency
  • ftFloat
  • ftBCD
  • ftLargeInt
  • ftSmallInt
  • ftWord
  • ftInteger
  • ftAutoInc (behave like ftInteger i.e. no auto-increment functionality)
  • ftDateTime
  • ftDate
  • ftTime
  • ftFmtBCD
  • ftWideString
  • ftFixedWideChar
  • ftBytes
  • ftVarBytes
  • ftBlob
  • ftMemo
  • ftWideMemo

TMemDataset implements common data manipulation methods such as: Append, AppendRecord, Insert, InsertRecord, Delete, Clear, and Refresh. TMemDataset implements Bookmarks and common navigation methods like: First, Next, Prior, Last, Locate, BOF, and EOF. Methods are provided that allow loading and saving both structure and data from a file, a stream, or another TDataset descendent.

TMemDataset provides methods to filter records, but they are implemented in a different manner than in TDataset. The Filter property is ignored; use the OnFilterRecord method and the Filtered property for this functionality.

One notable missing feature is Indexes. Index definitions are not implemented in TMemDataset.

TMemDataset uses ideas taken from the THKMemTab component by Harri Kasulke. (Hamburg/Germany)

Properties

Member Visibility Description
Active read only published Is the dataset open or closed.
AfterCancel read only published Event triggered after a Cancel operation.
AfterClose read only published Event triggered after the dataset is closed.
AfterDelete read only published Event triggered after a successful Delete operation.
AfterEdit read only published Event triggered after the dataset is put in edit mode.
AfterInsert read only published Event triggered after the dataset is put in insert mode.
AfterOpen read only published Event triggered after the dataset is opened.
AfterPost read only published Event called after changes have been posted to the underlying database.
AfterScroll read only published Event triggered after the cursor has changed position.
BeforeCancel read only published Event triggered before a Cancel operation.
BeforeClose read only published Event triggered before the dataset is closed.
BeforeDelete read only published Event triggered before a Delete operation.
BeforeEdit read only published Event triggered before the dataset is put in edit mode.
BeforeInsert read only published Event triggered before the dataset is put in insert mode.
BeforeOpen read only published Event triggered before the dataset is opened.
BeforePost read only published Event called before changes are posted to the underlying database.
BeforeScroll read only published Event triggered before the cursor changes position.
FieldDefs read only published Definitions of available fields in the underlying database.
FileModified read only public Indicates if the in-memory dataset has been modified.
FileName published File name used to read or write field definitions and optional data.
Filter read only public Filter to apply to the data in memory.
Filtered read only published Is the filter active or not.
See all Properties

Methods

Member Visibility Description
BookmarkValid public Test whether ABookMark is a valid bookmark.
Clear public Clears the content in the in-memory dataset.
CompareBookmarks public Compare two bookmarks.
CopyFromDataset public Loads field definitions and optional data from the specified TDataset.
Create public Create a new TDataset instance.
CreateBlobStream public Create blob stream.
CreateTable public Creates the internal storage for records in the in-memory dataset.
DataSize public Size of the internal TMemoryStream used in the in-memory dataset.
Destroy public Free a TDataset instance.
LoadFromFile public Loads the content for the dataset from the specified file name.
LoadFromStream public Loads the content for the dataset from the specified stream.
Locate public Locate a record based on some key values.
Lookup public Search for a record and return matching values.
SaveToFile public Saves field definitions and optional record data to the specified file name.
SaveToStream public Saves field definitions and optional record data to the specified stream.
See all Methods

Events

Member Visibility Description
OnDeleteError read only published Event triggered when a delete operation fails.
OnEditError read only published Event triggered when an edit operation fails.
OnFilterRecord read only published Event triggered to filter records.
OnNewRecord read only published Event triggered when a new record is created.
OnPostError read only published Event triggered when a post operation fails.
See all Events

See also

Name Description
TDataset Base class for records-based data-access.