TADMemTable Questions

The list of questions and answers related to TADMemTable.

QM1: TADMemTable vs. TClientDataSet – what is better ? I'm thinking of replacing all TClientDataSet with TADMemTable. Is a TADMemTable faster than a TClientDataSet?

A: It is MUCH faster. 

2 years ago we have posted this article. There you can find "Speed" section and the screen snapshot with benchmark results. The ADClientDataSet is AnyDAC v 1 in-memory table. So, the post is about AnyDAC v 1, but AnyDAC v 2 is faster than v 1. 

As you can see TClientDataSet is extremely slow dataset ... 


QM2: The nice thing with the TClientDataSet is that you can add, delete, change records and then process TClientDataSet.Delta. Is that possible with TADMemTable ?

A: The TADMemTable has the similar functionality. But it follows to the »Cached Updates« model. When CachedUpdates property value is True, then memtable will record changes in the updates journal. 

To post updates to a DB you have to use ApplyUpdates. To "merge change log" you have to call CommitUpdates

You can find description of these and other methods in the AnyDAC help file and the examples in the AnyDAC\Samples\Comp Layer\TADMemTable folder. 


QM3: I use clonecursor a lot with the clientdatasets. How I can do that with TADQuery ?

A: Use the following code: 


ADMemTable1.CloneCursor(ADQuery1, False, False);


QM4: How to create and populate ADMemTable ?

A: 1) Create the in-memory dataset 


with ADMemTable1.FieldDefs do begin
  with AddFieldDef do begin
    Name := 'f1';
    DataType := ftInteger;
  with AddFieldDef do begin
    Name := 'f2';
    DataType := ftString;
    Size := 50;
with ADMemTable1 do begin
  Fields[0].AsInteger := ...;
  Fields[1].AsString := ...;


2) Append data to it, browse / edit it. 


QM5: What is the fastest way to load a TADMemTable from a another DataSet (including structure) ?

A: The most simple way to copy the structure and the data from a TDataSet to a TADMemTable is to use the CopyDataSet method: 


ADMemTable1.CopyDataSet(DataSet1, [coStructure, coRestart, coAppend]);


QM6: How to copy all records from ADQuery into ADMemTable and edit them in the ADMemTable ?

A: You can do something like that: 


// UniDirectiona must be false if no
ADQuery1.FetchOptions.Undirectional := False;

ADMemTable1.Data := ADQuery1.Data;
while not ADMemTable1.Eof do begin


QM7: I cannot add a persistent field of type ftGUID. I am getting error about field size, but the field size control is disabled. What is wrong ?

A: That is known issue in DB.pas unit: The workaround is to create a GUID field at runtime.

What do you think about this topic? Send feedback!