You are not logged in.
Pages: 1
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
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
Pages: 1