#1 mORMot 1 » _JsonFast the first time is used is normal, but the second time is use » 2023-08-25 16:13:10

Americo079
Replies: 0

I have a function:

procedure TIntegraSupraMensagens.GetMonitoramentoSupraSystem(index: Integer; DI, DF: TDateTime);
var
  aReader: TDBXReader;
  FLoad: TObject;
begin
  try
    FLoad := TVIPForms.InputCarregando(sCARREGANDO, 'Carregando');
    with DmObservableMonitoramentoSupraSystem do
    begin
      cdsMonitoramentoSupra.DisableControls;
      cdsMonitoramentoSupra.Open;
      cdsMonitoramentoSupra.EmptyDataSet;
      aReader := serverMonitoramento.Recover(ProcessaIndex(index), DI, DF);
      try
        while aReader.Next do
        begin
          Application.ProcessMessages;
          cdsMonitoramentoSupra.Append;
          cdsMonitoramentoSupraID.Value         := aReader.Value['ID'].AsInt32;
          cdsMonitoramentoSupraSTATUS.Value     := ProcessarStatus(aReader.Value['STATUS'].AsInt32);
          cdsMonitoramentoSupraDTOJSON.AsString := aReader.Value['DTOJSON'].AsString;
          ProcessaEntidade(Index, cdsMonitoramentoSupraID.Value, _Json(aReader.Value['DTOJSON'].AsString));
          if VarIsVoid(aReader.Value['ERROMSG'].AsString) then
            cdsMonitoramentoSupraERROMSG.AsString := aReader.Value['ERROMSG'].AsString
          else
            cdsMonitoramentoSupraERROMSG.AsString := ProcessarMensagemErro(aReader.Value['ERROMSG'].AsString);
          cdsMonitoramentoSupraSYNCDATE.Value   := aReader.Value['SYNCDATE'].AsDateTime;
          cdsMonitoramentoSupraSYNCID.Value     := aReader.Value['SYNCID'].AsInt32;
          cdsMonitoramentoSupra.Post;
        end;
        cdsMonitoramentoSupra.EnableControls;
      except
        on E: Exception do
          TVIPException.Create(E);
      end;
    end;
  finally
    FreeAndNil(FLoad);
  end;
end;

When passing through aReader.Next for the first time, it returns the correct information. However, when it reaches:

ProcessaEntidade(Index, cdsMonitoramentoSupraID.Value, _Json(aReader.Value['DTOJSON'].AsString));

The ProcessaEntidade function receives the value unassigned for the JSON on the second pass.

Board footer

Powered by FluxBB