Cache current DataSet and restore inside loop

Discussion of open issues, suggestions and bugs regarding MyDAC (Data Access Components for MySQL) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
BKeffer
Posts: 6
Joined: Tue 23 Jan 2018 19:45

Cache current DataSet and restore inside loop

Post by BKeffer » Tue 23 Jan 2018 19:56

Hey guys!

I'm currently thinking about to buy this nice component. But first I want to make sure If it is the right tool.

So, my question is the following:
How is it possible to save the current MyTable-state while you loop through the dataset. What I mean is

Code: Select all

  FAutomat.OrderFields:= 'recno ASC';
  FAutomat.Open;
  while not FAutomat.Eof do
  begin
    FAutomat.PushState; // thats what I'm looking for -> should save the state

    // Do a different select
    FAutomat.AddWhere('name="Test"');   
    FAutomat.Open;

    FAutomat.PopState; // should restore the pushed state
  end;
As you can see, the state of the dataset should be the same like before pushsate and after popstate.

Can you guys help me? Would be very nice!

Best regards
Benjamin

BKeffer
Posts: 6
Joined: Tue 23 Jan 2018 19:45

Re: Cache current DataSet and restore inside loop

Post by BKeffer » Wed 24 Jan 2018 11:31

I was thinking about somthing like this:

Code: Select all

procedure TMyTable.PushState;
var Batch: TCRBatchMove;
begin
  FPushedDataSet:= TVirtualTable.Create(nil);
  Batch:= TCRBatchMove.Create(nil);
  Batch.Source:= Self;
  Batch.Destination:= FPushedDataSet;
  Batch.Execute;

  FPos:= Self.CurrentRecord;
  FConditions:= Self.Conditions;
  FOrder:= Self.OrderFields;
end;

procedure TMyTable.PopState;
begin
  Self.Conditions:= FConditions;
  Self.OrderFields:= FOrder;
  Self.SetCurrentRecord(FPos);

  Self.Data:= FPushedDataSet.GetData;
end;
However, this doesn't work :-/ Any help?

ViktorV
Devart Team
Posts: 3168
Joined: Wed 30 Jul 2014 07:16

Re: Cache current DataSet and restore inside loop

Post by ViktorV » Wed 24 Jan 2018 15:45

To solve your task, you better use a separate dataset for executing additional queries.

BKeffer
Posts: 6
Joined: Tue 23 Jan 2018 19:45

Re: Cache current DataSet and restore inside loop

Post by BKeffer » Wed 24 Jan 2018 16:15

Thanks for your reply!

And in general, how can I copy one DataSet to another (only in memory)?

ViktorV
Devart Team
Posts: 3168
Joined: Wed 30 Jul 2014 07:16

Re: Cache current DataSet and restore inside loop

Post by ViktorV » Thu 25 Jan 2018 09:07

To solve your task, you can assign a TMyQuery (TMyTable) to a TVirtualTable. You can read about to fill TVirtualTable with data from another TDataSet component in the VirtualTable help: https://www.devart.com/virtualdac/docs/ ... bject).htm

BKeffer
Posts: 6
Joined: Tue 23 Jan 2018 19:45

Re: Cache current DataSet and restore inside loop

Post by BKeffer » Thu 25 Jan 2018 16:16

Thank you!

ViktorV
Devart Team
Posts: 3168
Joined: Wed 30 Jul 2014 07:16

Re: Cache current DataSet and restore inside loop

Post by ViktorV » Thu 25 Jan 2018 16:32

Thank you for the interest in our products.
If you have any questions during using our products, please don't hesitate to contact us - and we will try to help you solve them.

Post Reply