#1 2021-04-14 16:53:46

leus
Member
Registered: 2012-09-05
Posts: 79

TSynSQLTableDataSet

I have a function that returns a Dataset to be used in some grid in my code. However, I've found out that I don't understand the life cycle of some variables.

  // TSomething is a TSQLRecord descendant
  b := TSomething.CreateAndFillPrepare(ServerDB, Where, [], Params,
    'FieldA,FieldB,FieldC');
  try
    Result := TSynSQLTableDataSet.CreateOwnedTable(AOwner, b.FillTable); // using CreateTable instead of CreateOwnedTable leaks
  finally
    // Freeing this variable makes it AV
    // b.Free;
  end;

How can I return a DataSet without leaking that TSQLRecord descentand? Shoud I just keep a reference around to free it when the dataset is also freed? Is there a better way to return a TDataSet so my DevExpress grid keeps working?

Offline

#2 2021-04-14 17:07:58

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,238
Website

Re: TSynSQLTableDataSet

Don't use CreateAndFillPrepare, but directly a local TSQLTableJSON instance, from ServerDB.

Offline

#3 2021-04-21 22:44:58

leus
Member
Registered: 2012-09-05
Posts: 79

Re: TSynSQLTableDataSet

Interesting. I've replaced the above part with this, and it appears not to leak, and it seems to be working correctly:

  var
    aList: TSQLTableJSON;
  begin
    aList := ServerDB.MultiFieldValues(TSomething, Fields, Where, [], Params);
    if aList <> nil then
      Result := TSynSQLTableDataSet.CreateOwnedTable(AOwner, aList);
...

Last edited by leus (2021-04-21 22:45:46)

Offline

Board footer

Powered by FluxBB