I'm starting in the DataSnap world and I came across a situation that can not find a solution.
My code is with memory leak, because I can not release the objects. if I release the objects the access error violated in the result.
function TServerMethods1.Teste(Key: string; ID: Integer): TFDJSONDataSets;
var
Con : TFDConnection;
qry : TFDQuery;
begin
Con:= TFDConnection.Create(nil);
qry:= TFDQuery.Create(nil);
try
qry.Connection:= Con;
qry.SQL.Text:= Format('select id, nome from clientes where id = %d', [ID]);
qry.Open;
Result:= TFDJSONDataSets.Create;
TFDJSONDataSetsWriter.ListAdd(Result, qry);
finally
FreeAndNil(qry);
FreeAndNil(Con);
end;
end;
I need to release the created objects [qry, con] but I can not.