CalcFields

Hi when i open the TXDataWebDataSet (wdTOrd) with calcfields event assigned i have the error on the image. Can you help me ?

// -----------------------------------------------------------------------------
procedure TDM0.wdTOrdCalcFields(DataSet: TDataSet);
begin
  DataSet.FieldByName('Data_Asp').AsDateTime:=DataSet.FieldByName('Data_Ora_Asp').AsDateTime;
  DataSet.FieldByName('Ora_Asp').AsDateTime:=DataSet.FieldByName('Data_Ora_Asp').AsDateTime;
end;

Please send a project reproducing the issue. We really can't guess what is going on.
The error message indicates you are dealing with some null data, but if you can't debug there to check if some of the fields you are dealing with are null or not, we need a sample project.

the problem is the state edit or insert of dataset. in fact if i use

If Dataset.State In [dsEdit,dsInsert] Then Begin
DataSet.FieldByName('Data_Asp').AsDateTime:=DataSet.FieldByName('Data_Ora_Asp').AsDateTime;
 DataSet.FieldByName('Ora_Asp').AsDateTime:=DataSet.FieldByName('Data_Ora_Asp').AsDateTime;
End;

go fine when i insert a new rec but after i cant have a values of that fields.

See this code : in aftrer open of dataset i decide to insert a new record and i think the error happen when dataset "opening" before fire after open event !!
See the end of code : I tryed to attach the wdTOrd.OnCalcFields:=wdTOrdCalcFields; BUT error happen always... THEN i think this happen during open dataset.

procedure TDM0.wdTOrdAfterOpen(DataSet: TDataSet);
Var QryCli:String;
  DataResponse:TXDataClientResponse;
  ResData:TaStrings;
begin
  If orOper = orNEW Then Begin
    DataSet.Insert();  // vedi anche wdTOrdNewRecord
     ....
  End;
  If orOper = orMOD Then Begin
    wdROrd.Close();
    wdROrd.QueryString:=Format('$filter=(PK_1 eq %d)&$orderby=Pos_Rigo',[DataSet.FieldByName('PK_1').AsInteger]);
    wdROrd.Load();  // fire : wdROrdAfterOpen
  End;

  wdTOrd.OnCalcFields:=wdTOrdCalcFields;
end;

Can you please send a minimal project reproducing the issue?

Wagner is too hard for me now to create a minimal proj because no time ... sorry BUT i discovered one thing :

With wdTOrd Do Begin
    Close();
    //SetJsonData('{}');   <- this give me problem on CalcFiels event
    Open();  

i hope this help you !

I've always problem with calcfields when i edit record ...

Attached sample : when start main try to edit the phone number 999-9999 and see fields below that hide , these are calcfields !!
Ristord.zip (3.1 MB)

NOTE : archive is .RAR type

// -----------------------------------------------------------------------------
// NB : se c'è un SetJsonData('{}'); il calfields dà problemi di assegnazione valori null
// in realtà si tratta di una questione di wdTOrd.State(dsEdit, dsInsert)
procedure TDM0.wdTOrdCalcFields(DataSet: TDataSet);
begin
DataSet.FieldByName('Data_Asp').AsDateTime:=DataSet.FieldByName('Data_Ora_Asp').AsDateTime;
 DataSet.FieldByName('Ora_Asp').AsDateTime:=DataSet.FieldByName('Data_Ora_Asp').AsDateTime;
end;

news for me ? did you test my sample ?

You are calling DM0.wdTOrd.Post in WebFormCreate, thus the dataset is not in edit mode anymore. If you want to keep editing it, you should keep the record in edit mode.

pas2js team confirms possible issue with the underlying dataset and is investigating this.

1 Like

Corrected the problem ?

From the version history

Fixed : Issue with JSONDataSet calculated fields handling (9/12/2021)