When I have a ClientDataset with datetime fields and decimal(5,2) fields, Delphi 10.4 can't show them on a TDBGrid, it raises a convert exception.
I have prepared an small test project to show this error (my real data comes from SQL Server, although I can get the same error filling the Clientdataset manually).
procedure TForm1.FormCreate(Sender: TObject);
var ClientDataset: TClientDataset;
Datasource: TDatasource;
DBGrid: TDBGrid;
begin
ClientDataset := TClientDataset.Create(Self);
ClientDataset.FieldDefs.Add('Id', ftInteger);
ClientDataset.FieldDefs.Add('Date', ftDateTime);
ClientDataset.FieldDefs.Add('Decimal', ftBCD, 2);
ClientDataset.FieldDefs.Find('Decimal').Precision := 5;
ClientDataset.CreateDataSet;
Datasource := TDatasource.Create(Self);
Datasource.Dataset := ClientDataset;
ClientDataset.Insert;
ClientDataset.FieldValues['id'] := 1;
ClientDataset.FieldValues['Date'] := Now;
ClientDataset.FieldValues['Decimal'] := 7.55;
ClientDataset.Post;
ClientDataset.Insert;
ClientDataset.FieldValues['id'] := 2;
ClientDataset.FieldValues['Date'] := Now;
ClientDataset.FieldValues['Decimal'] := 8.2;
ClientDataset.Post;
DBGrid := TDBGrid.Create(Self);
DBGrid.Parent := Self;
DBGrid.Align := alClient;
DBGrid.Datasource := Datasource;
end;
It raises this exception: '8200@' is not a valid integer value
A decimal(18,2) doesn't have this problem, if I comment the line ClientDataset.FieldDefs.Find('Decimal').Precision := 5;
then no error is raised.
Also, if there is no datetime field then no error is raised either. This runs fine:
procedure TForm1.FormCreate(Sender: TObject);
var ClientDataset: TClientDataset;
Datasource: TDatasource;
DBGrid: TDBGrid;
begin
ClientDataset := TClientDataset.Create(Self);
ClientDataset.FieldDefs.Add('Id', ftInteger);
ClientDataset.FieldDefs.Add('Decimal', ftBCD, 2);
ClientDataset.FieldDefs.Find('Decimal').Precision := 5;
ClientDataset.CreateDataSet;
Datasource := TDatasource.Create(Self);
Datasource.Dataset := ClientDataset;
ClientDataset.Insert;
ClientDataset.FieldValues['id'] := 1;
ClientDataset.FieldValues['Decimal'] := 7.55;
ClientDataset.Post;
ClientDataset.Insert;
ClientDataset.FieldValues['id'] := 2;
ClientDataset.FieldValues['Decimal'] := 8.2;
ClientDataset.Post;
DBGrid := TDBGrid.Create(Self);
DBGrid.Parent := Self;
DBGrid.Align := alClient;
DBGrid.Datasource := Datasource;
end;
Do you think that this could be fixed without having to replace all my decimal(5,2) fields with decimal(18,2) fields ?.
UPDATE: This is a problem specific of the ClientDataset. If I open the same data on a TADOQuery or TFDMemTable (with the exact same datetime and decimal(5,2) BCD fields), Delphi 10.4 shows the DBGrid without any issue.
The problem is also specific of the DBGrid. There is no problem displaying those fields on DBEdits.
I reported the bug and now has been fixed in the recent Delphi 10.4 Update 1.