Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 4 of 4 total
Thread Can I modify a DataSet without storing the changes?
Sat, May 5 2018 4:36 PMPermanent Link

Ralf Mimoun

Hi all,

I need some filter functionality for a dataset. No problem with some placeholders in the SQL statement. Unfortunately, that means a Database.LoadRows to get the filtered data and another Database.LoadRows everytime you open the filter value dialog it can show all column values.

I'd like to load the data only once and do the rest with a second DataSet, GetRows and LoadRows. Works like a charm, I just have to delete the rows that are filtered out from the second DataSet. But then it tries to delete that row from the read dataset on the web server.

So is there a way to get an unbound / "in memory" dataset without that hurry to store the data somewhere else?
Sat, May 5 2018 7:12 PMPermanent Link

Ralf Mimoun

I just looked into the source code. A virtual TDatabase.Commit method could help. Then you could write a TSinkDatabase classe with an almost empty Commit.

And then I found a solution. It's not that elegant, but it seems to work good enough for me. So, if you need a 100% "in memory" dataset to add some rows, filter data from another dataset (DataSet2.LoadColumns(DataSet1.GetColumns) + DataSet2.LoadRows(DataSet1.GetRows) work great!) or whatever, you just have to create a second Database object:

 SinkDatabase := TDatabase.Create(Application);
 SinkDatabase.BeforeCommit := SinkDatabaseBeforeCommit;
 SinkDataSet := TDataSet.Create(SinkDataBase);
// If you want to mirror the structure and content of an existing DataSet
 SinkDataSet.DataSetName := SourceDataSet.DataSetName;
 SinkDataSet.LoadColumns(SourceDataSet.GetColumns);
 SinkDataSet.Open;
 SinkDataSet.LoadRows(SourceDataSet.GetColumns);
// Now do whatever you want

and

function TForm1.SinkDatabaseBeforeCommit(Sender: TObject): Boolean;
begin                                  
 Result := False;
end;

That's all, just don't forget to free SinkDatabase and SinkDataSet somewhere. Now nothing goes to the database at the web servers end.
Sat, May 5 2018 8:44 PMPermanent Link

Walter Matte

Tactical Business Corporation

See AutoTransactions

If you set AutoTransaction to false it will not do the commit automatically

Then after your filter turn AutoCommit back on.  I do it all the time.

Walter
Sun, May 6 2018 3:33 AMPermanent Link

Ralf Mimoun

Yes, that works too and is way easier to use SmileThanks for the hint!
Image