0

I have the following structure:

A function in a class to load some data:

function TClasseDatasnap.BuscarEmpresas(var Dataset: TFDJSONDataSets): Boolean;
begin
  Try
    Try
      F_ClientModule := TF_ClientModule.Create(nil);
      Dataset := F_ClientModule.ServerMethods1Client.GetDadosEmpresa(0);
      Result := True;
    Except
      On E:Exception do
      Begin
        Result := False;
        TModelTratamentoErro.GetInstance.TratarErro(nil,E);
      End;
    End;
  Finally
    FreeAndNil(F_ClientModule);
  End;
end;

And in my form i call the function passing the var DadosEmpresa as parameter:

procedure TF_Login.BuscarEmpresas;
var
  DadosEmpresa: TFDJSONDataSets;
begin
  { F2.4.1 }
  if TClasseDatasnap.GetInstance.BuscarEmpresas(DadosEmpresa) then
  Begin
    Mem_Empresas.Close;
    Mem_Empresas.AppendData(TFDJSONDataSetsReader.GetListValue(DadosEmpresa, 0));
    Mem_Empresas.Open;
  End;
end;

Getting data from datasnap works perfectly, however when the program arrives on the line:

Mem_Empresas.AppendData(TFDJSONDataSetsReader.GetListValue(DadosEmpresa, 0));

The following error is raised:

Project XXX.exe raised exception class EArgumentOutOfRangeException with message 'Argument out of range'.

If I comment the line FreeAndNil(F_ClientModule);, the program works perfectly.

I know that F_ClientModule is responsible for making the requests to the datasnap server, but I've already passed the data I received to a variable, am I doing something wrong?

Tallys Ferrante
  • 173
  • 1
  • 13

0 Answers0