RawInvokeAsync in on new record event

If i use RawInvokeAsync in new record event i have this error :

image

// -----------------------------------------------------------------------------
procedure TDM0.wdTOrdNewRecord(DataSet: TDataSet);
Var QryCli:String;
DataResponse:TXDataClientResponse;
ResData:TaStrings;
begin
DataSet.FieldByName('ORD_RISTO_R').Value:=TJSArray.New();
DataSet.FieldByName('Cod_CliFor').AsString:=CodUtente;
DataSet.FieldByName('Inizio_Ins').AsDateTime:=Now();

// Cerca un ordine già aperto per l'utente loggato, altrim. lo inserisce nuovo
QryCli:=Format(
'SELECT Cognome, Nome, Indirizzo, Citta, Prov, CAP, Telef_1, Telef_2, Part_IVA, Cod_Fisc FROM Clienti_Priv '+
'WHERE Cod_Cli = ''%s'' ', [CodUtente]);
DataResponse:=AWait(wdcData.RawInvokeAsync('IDataService.Call_ServiceWeb',['QRY_SEL',QryCli,-1]));

// NB : il nome del campo di ritorno è casesensitive, deve essere maiuscolo
ResData:=GetJsonValues(String(DataResponse.Result),
['COGNOME','NOME','INDIRIZZO','CITTA','PROV','CAP','TELEF_1','TELEF_2','PART_IVA','COD_FISC']);

If Length(ResData) > 0 Then Begin
DataSet.FieldByName('Rag_Soc_1').AsString:=ResData[0];
DataSet.FieldByName('Rag_Soc_2').AsString:=ResData[1];
DataSet.FieldByName('Indirizzo').AsString:=ResData[2];
DataSet.FieldByName('Citta').AsString:=ResData[3];
DataSet.FieldByName('Prov').AsString:=ResData[4];
DataSet.FieldByName('CAP').AsString:=ResData[5];
DataSet.FieldByName('Telef_1').AsString:=ResData[6];
DataSet.FieldByName('Telef_2').AsString:=ResData[7];
End;
end;

news for me ?

I fail to see what does it have to do with RawInvokeAsync? Why do you think the error is there? The console indicates the error is in some TField.AsString call.

ResData[x] contains the value as string returned by DataResponse and i'm trying to assign that to TField BUT the assignment fail because RawInvokeAsync leads to failure completely the OnNewRec event ... in fact if i remove or comment those instruction all go fine !!

We need exact information. Your console doesn't indicate an error in RawInvoke. Please provide the line numbers of your code so we can tell exactly the line of the error. My guess is your ResData array is incorrect. Inspect your ResData variable after is filled and please provide a print with their values here.

Values in ResData are rigth ... maybe is a ResData:=GetJsonValues( that i use :

// -----------------------------------------------------------------------------
Function GetJsonValues(JsonString:String; FldNames:TaStrings; xData:TXDataWebDataSet = Nil):TaStrings;
Var JsonValues,JsonRecs:TJSONValue;
  JsonMain:TJSONObject;
  I,j:Integer;
  CurrFld:String;
Begin
  Try Try
    SetLength(Result,0);
    // Sistema proposto da TMS, ma non funziona mi dà records in tabella 'vuoti' senza dati
    //Var JFDBS: TJSObject; JManager: TJSObject; JTableList: TJSObject; JRowList: TJSArray;
    //JFDBS := TJSObject(TJSObject(TJSJson.Parse(JsonString))['FDBS']);
    //JManager := TJSObject(JFDBS['Manager']);
    //JTableList := TJSObject(TJSArray(JManager['TableList'])[0]);
    //JRowList := TJSArray(JTableList['RowList']);
    // xData.SetJSonData(JRowList);

    JsonMain:=TJSonObject.Create();
    JsonValues:=JsonMain.ParseJSONValue(JsonString);  // Non usare Uppercase, dà errore di parsing !
    JsonValues:=(JsonValues As TJSONObject).Get('FDBS').JSONValue;
    //WebMemo1.Text:=(vJSONScenario as TJSONObject).Get('Version').JSONValue.Value;
    JsonValues:=(JsonValues As TJSONObject).Get('Manager').JSONValue;
    //WebMemo1.Text:=(vJSONScenario as TJSONObject).Get('UpdatesRegistry').JSONValue.Value;
    JsonValues:=(JsonValues As TJSONObject).Get('TableList').JSONValue;
    // Prendo il rowlist della tabella nr 1 (idx = 0)
    JsonValues:=TJSONObject((JsonValues As TJSONArray).Items[0]).Get('RowList').JSONValue;

    If xData <> Nil Then Begin
      // NB : Il xData.close in certi casi dà un errore di Undefined Data initrecord....
      If xData.Active Then Begin // svuoto tutto e ricarico
        While Not xData.IsEmpty() Do
          xData.Delete();
      End Else
        xData.Open();
    End;

    For i:=0 To (JsonValues As TJSONArray).Count-1 Do Begin
      JsonRecs:=TJSONObject((JsonValues As TJSONArray).Items[i]).GetValue('Original');

      If JsonRecs <> Nil Then Begin
        If xData <> Nil Then Begin
          xData.Insert();

          For j:=0 To xData.FieldCount-1 Do Begin
            CurrFld:=UpperCase(xData.Fields[j].FieldName);
            //Console.Log(CurrFld);
            If TJSONObject(JsonRecs).GetValue(CurrFld) <> Nil Then Begin
              // Console.Log(CurrFld + ' val '+TJSONObject(JsonRecs).GetValue(CurrFld).Value);
              If xData.Fields[j].DataType In [ftString] Then
                xData.FieldByName(CurrFld).Value:=
                  TJSONObject(JsonRecs).GetValue(CurrFld).Value
              Else If xData.Fields[j].DataType In [ftInteger] Then
                xData.FieldByName(CurrFld).Value:=
                  StrToInt(TJSONObject(JsonRecs).GetValue(CurrFld).Value)
              Else If xData.Fields[j].DataType In [ftFloat] Then
                xData.FieldByName(CurrFld).Value:=
                  StrToFloat(TJSONObject(JsonRecs).GetValue(CurrFld).Value)
              Else If xData.Fields[j].DataType = ftDateTime Then
                xData.FieldByName(CurrFld).Value:=
                  JSONDateTime_To_Datetime(TJSONObject(JsonRecs).GetValue(CurrFld).Value);
            End;
          End;
          xData.Post();
        End Else Begin
          For j:=0 To Length(FldNames)-1 Do Begin
            CurrFld:=FldNames[j];

            If TJSONObject(JsonRecs).GetValue(CurrFld) <> Nil Then Begin
              SetLength(Result,Length(Result)+1);
              Result[Length(Result)-1]:=TJSONObject(JsonRecs).GetValue(CurrFld).Value;
            End;
          End;
        End;
      End;
    End;
  Except
    On E:Exception Do
      Raise E.Create('GetJsonValues error : '+E.Message+' Field : '+CurrFld);
  End;
  Finally
    JsonMain.Free();
  End;
End;

Wagner follow me ... note RAWINVOKEASYNC block : if i comment this all go fine else give me error showed below THEN is a RawInvokeAsync in a new record event that do this problem !!

// -----------------------------------------------------------------------------
procedure TDM0.wdTOrdNewRecord(DataSet: TDataSet);
Var QryCli:String;
  DataResponse:TXDataClientResponse;
  ResData:TaStrings;
begin
  DataSet.FieldByName('ORD_RISTO_R').Value:=TJSArray.New();
  DataSet.FieldByName('Cod_CliFor').AsString:=CodUtente;
  DataSet.FieldByName('Inizio_Ins').AsDateTime:=Now();
  DataSet.FieldByName('Data_Doc').AsDateTime:=Now();
  DataSet.FieldByName('Data_Ora_Asp').AsDateTime:=Now();
  DataSet.FieldByName('Dest_Div').AsBoolean:=False;

{ **RAWINVOKEASYNC block**
  QryCli:=Format(
    'SELECT Cognome, Nome, Indirizzo, Citta, Prov, CAP, Telef_1, Telef_2, Part_IVA, Cod_Fisc FROM Clienti_Priv '+
    'WHERE Cod_Cli = ''%s'' ', [CodUtente]);
  DataResponse:=AWait(wdcData.RawInvokeAsync('IDataService.Call_ServiceWeb',['QRY_SEL',QryCli,-1]));
}

  DataSet.FieldByName('Rag_Soc').AsString:='ddd';

end;

How do you know that? You didn't send a print. You didn't send the line numbers I asked. Your code changes in every post you make. That's difficult for us.
Please try to isolate your problem in a very small project reproducing the issue then send it to us, this way we can check it in a more productive way.

excuse me wagner see only my last post with " RAWINVOKEASYNC block" ... i think have been clear with the problem. Its simple : New record event fail if is into a RawInvokeAsync !!

SOLVED in another way : i moved those instruction in afteropen event like this :

procedure TDM0.wdTOrdAfterOpen(DataSet: TDataSet);
Var QryCli:String;
  DataResponse:TXDataClientResponse;
  ResData:TaStrings;
begin
   DataSet.Insert();

    // Recupera le informazioni del cliente
    QryCli:=Format(
      'SELECT Cognome, Nome, Indirizzo, Citta, Prov, CAP, Telef_1, Telef_2, Part_IVA, Cod_Fisc FROM Clienti_Priv '+
      'WHERE Cod_Cli = ''%s'' ', [CodUtente]);
    DataResponse:=AWait(wdcData1.RawInvokeAsync('IDataService.Call_ServiceWeb',['QRY_SEL',QryCli,-1]));

..... and so on ...

1 Like