How to aggregate records from multiple datasets

hi,
i have a x:TDAMemDataTable
now i have several x’s created who all hold some records
i want to aggregate all those records in a new x
so basically
y = new x
for xlist
y.CopyRecordSet(xlist[i])

i would have expected y to contain all recs from all x’s
is there another method that i can use to kinda ‘clone’ reords into a new combined memtable?

tia,
marc

Hi,

check sample:
testcase.zip (24.6 KB)

well i’m using

CloneSelectedRecord(dataset)

now which seems to do the job, i need to alter the primkey of the cloned record (otherwise i have duplicate pk’s and that does not work in the code that follows)
but thx for the sample, it’ll come in handy…

Hi,

If table has PK, it will merge data correctly :slight_smile:

updated testcase with PK. testcase.zip (24.6 KB)

thx
will try

why doesn’t cloneSelectedRecord insert the record at the end of the dataset?
it seems it’s inserting before the cursor…

Hi,

it uses Insert internally.

so no append…

Hi,

you can do own code that do:

  • GetBookmark
  • Last
  • CloneSelectedRecord
  • GotoBookmark
    or create own code based on CloneSelectedRecord

even when using Last the record does not get inserted at the end (that’s why i asked :slight_smile: )
so now cloneselected always insert at the front, and i’m sorting the dataset afterwards which gives the desired result
but i would have expected Last to do the trick also (i don’t need the bookmark since i’m aggregating datasets)

Hi,

create custom method with Append and use it via class helper like

procedure TDataTableHelper.MyCloneSelectedRecord(const Source: IDADataset; DoPost: boolean = True);
...
begin
  Append; // was Insert
...
end;

1 Like

hi Evgeny,

is there a way to ‘sort’ the damemtable based on the hidden RecID field?

Hi,

you can use something like

  DAMemDataTable1.Sort(['RecID'], [sdAscending]);

:slight_smile: that’s what i’m doing but i expected something else i guess…

Hi,

what exactly?

some kind of internalsort for recID
but no problem, it works
the only thing i see is that sorting changes the value of the RecId field itself…
if i cloneselectedrecord and the value in the original is 2 and 4 for example, sorting will result in 1 and 2
which isn’t a problem but if you would ever change that my code will break…

Hi,

you can use

  DAMemDataTable1.Sort([],[]);

I think, it is suitable for you

1 Like