Random value assignement for fields with OnValidate event

Discussion of open issues, suggestions and bugs regarding SDAC (SQL Server Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
m.deltoso
Posts: 9
Joined: Wed 10 Dec 2014 09:19

Random value assignement for fields with OnValidate event

Post by m.deltoso » Tue 21 Jul 2015 08:44

Dear Devart,

we have a strange but very serious problem using your components (both version 7.1.5 and 7.1.6) with Delphi XE8.

In particular we noticed that if we assign a value to a field of a TMSQuery component in OnNewRecord event and that field has an OnValidate event, after the OnValidate event the field has a random value different from the value assigned in code.

We created a simple example project based on a TMSConnectio, a TMSQuery linked to a standard TDBGrid through a TDataSource. The Query text of the TMSQuery component is a simple select on Sales.SalesOrderHeader table of AdventureWorks2014 database. We create a list of custom fields to replicate a little portion of fields of a table of our database. As you can see in the code, when you press the button, a list of ten rows are appended to the empty TMSQuery component. For each row, in the OnNewRecord event we assign values for memRigheID_TIPO_RIGA, memRigheCOD_ARTICOLO and memRigheTEST fields of the TMSQuery component. For both fields memRigheID_TIPO_RIGA and memRigheCOD_ARTICOLO we create an OnValidate event which changes the value of other fields of the TMSQuery, to simulate a standard behaviour of our software. As you can see in the TdbGrid, the integer value 2 assigned to memRigheID_TIPO_RIGA field is changed to a random integer value (something like 1048578 for us) and the string value 'A001' is changed to a strange string value (some string which is not printable). The string value 'Test' assigned to memRigheTEST (which has not an OnValidate event) is unchanged and correctly assigned.

Unit6.pas

Code: Select all

unit Unit6;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Data.DB, Vcl.Grids, Vcl.DBGrids, DBAccess, MSAccess, MemDS, Vcl.StdCtrls;

type
  TForm6 = class(TForm)
    dtsRighe: TDataSource;
    Button1: TButton;
    memRighe: TMSQuery;
    memRigheID_TIPO_RIGA: TIntegerField;
    memRigheCOD_ARTICOLO: TStringField;
    memRigheIMPORTO: TCurrencyField;
    memRigheTEST: TStringField;
    memRigheNRO_RIGA: TIntegerField;
    MSConnection1: TMSConnection;
    memRigheQTA_BCD: TFMTBCDField;
    memRigheQTA_FMT_BCD: TFMTBCDField;
    DBGrid1: TDBGrid;
    procedure Button1Click(Sender: TObject);
    procedure memRigheNewRecord(DataSet: TDataSet);
    procedure memRigheCOD_ARTICOLOValidate(Sender: TField);
    procedure memRigheID_TIPO_RIGAValidate(Sender: TField);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form6: TForm6;

implementation

{$R *.dfm}

procedure TForm6.Button1Click(Sender: TObject);
var
  i: Integer;
begin
  memRighe.Close;
  memRighe.Open;
  for i := 1 to 10 do
  begin
    memRighe.Append;
    memRigheNRO_RIGA.AsInteger := i;
    memRighe.CheckBrowseMode;
  end;
end;

procedure TForm6.memRigheCOD_ARTICOLOValidate(Sender: TField);
begin
  memRigheQTA_FMT_BCD.AsCurrency := 20;
end;

procedure TForm6.memRigheID_TIPO_RIGAValidate(Sender: TField);
begin
  memRigheQTA_BCD.AsCurrency := 10;
end;

procedure TForm6.memRigheNewRecord(DataSet: TDataSet);
begin
  memRigheID_TIPO_RIGA.AsInteger := 2;
  memRigheCOD_ARTICOLO.AsString := 'A001';
  memRigheTEST.AsString := 'Test';
end;

end.
unit6.dfm

Code: Select all

object Form6: TForm6
  Left = 0
  Top = 0
  Caption = 'Form6'
  ClientHeight = 295
  ClientWidth = 834
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'Tahoma'
  Font.Style = []
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 13
  object Button1: TButton
    Left = 544
    Top = 24
    Width = 75
    Height = 25
    Caption = 'Button1'
    TabOrder = 0
    OnClick = Button1Click
  end
  object DBGrid1: TDBGrid
    Left = 0
    Top = 177
    Width = 834
    Height = 118
    Align = alBottom
    DataSource = dtsRighe
    TabOrder = 1
    TitleFont.Charset = DEFAULT_CHARSET
    TitleFont.Color = clWindowText
    TitleFont.Height = -11
    TitleFont.Name = 'Tahoma'
    TitleFont.Style = []
  end
  object dtsRighe: TDataSource
    DataSet = memRighe
    Left = 245
    Top = 18
  end
  object memRighe: TMSQuery
    Connection = MSConnection1
    SQL.Strings = (
      'SELECT'
      '  CAST(0 AS INT) AS ID_TIPO_RIGA,'
      '  '#39'12345678901234567890'#39' AS COD_ARTICOLO,'
      '  CAST(0 AS DECIMAL (16,4)) AS QTA_BCD,'
      '  CAST(0 AS DECIMAL (16, 4)) AS QTA_FMT_BCD,'
      '  '#39'12345678901234567890'#39' AS TEST,'
      '  CAST(0 AS INT) AS NRO_RIGA'
      'FROM'
      '  sALES.SalesOrderHeader'
      'WHERE'
      '  (1=2)       ')
    CachedUpdates = True
    OnNewRecord = memRigheNewRecord
    Left = 176
    Top = 24
    object memRigheID_TIPO_RIGA: TIntegerField
      FieldName = 'ID_TIPO_RIGA'
      OnValidate = memRigheID_TIPO_RIGAValidate
    end
    object memRigheCOD_ARTICOLO: TStringField
      FieldName = 'COD_ARTICOLO'
      OnValidate = memRigheCOD_ARTICOLOValidate
    end
    object memRigheIMPORTO: TCurrencyField
      FieldKind = fkCalculated
      FieldName = 'IMPORTO'
      Calculated = True
    end
    object memRigheTEST: TStringField
      FieldName = 'TEST'
    end
    object memRigheNRO_RIGA: TIntegerField
      FieldName = 'NRO_RIGA'
    end
    object memRigheQTA_BCD: TFMTBCDField
      FieldName = 'QTA_BCD'
      Precision = 16
      Size = 4
    end
    object memRigheQTA_FMT_BCD: TFMTBCDField
      FieldName = 'QTA_FMT_BCD'
      Precision = 16
      Size = 4
    end
  end
  object MSConnection1: TMSConnection
    Database = 'AdventureWorks2014'
    Options.NumericType = ntFmtBCD
    Username = 'sa'
    Server = '.'
    Connected = True
    Left = 56
    Top = 16
  end
end
We notice that strange behaviour only using your components (both version 1.7.5 and 1.7.6) with Delphi XE8, because the same code compiled with Delphi XE7 worked great.

We hope you can replicate this bug and correct it quickly because we have to switch to Delphi XE8 continuing to use your SDAC great components as soon as possible.

I wait for news soon.

Thanks in advance,

Sh Servizi

azyk
Devart Team
Posts: 1057
Joined: Fri 11 Apr 2014 11:47
Location: Alpha Centauri A

Re: Random value assignement for fields with OnValidate event

Post by azyk » Mon 27 Jul 2015 08:21

Thank you for the information. We have reproduced this problem and are investigating it. We will notify you about the results as any are available.

m.deltoso
Posts: 9
Joined: Wed 10 Dec 2014 09:19

Re: Random value assignement for fields with OnValidate event

Post by m.deltoso » Mon 24 Aug 2015 13:12

Are there any news on the reported problem?

azyk
Devart Team
Posts: 1057
Joined: Fri 11 Apr 2014 11:47
Location: Alpha Centauri A

Re: Random value assignement for fields with OnValidate event

Post by azyk » Thu 27 Aug 2015 11:26

We have fixed this problem. This fix will be included in the next SDAC build.

m.deltoso
Posts: 9
Joined: Wed 10 Dec 2014 09:19

Re: Random value assignement for fields with OnValidate event

Post by m.deltoso » Fri 28 Aug 2015 16:05

When does the next release will be available?

azyk
Devart Team
Posts: 1057
Joined: Fri 11 Apr 2014 11:47
Location: Alpha Centauri A

Re: Random value assignement for fields with OnValidate event

Post by azyk » Mon 31 Aug 2015 08:28

SDAC release is planned within two weeks.

psycodad
Posts: 5
Joined: Wed 02 Apr 2008 10:06
Location: Switzerland

Re: Random value assignement for fields with OnValidate event

Post by psycodad » Tue 01 Sep 2015 12:20

Exact the same behaviour here (XE8). After "OnValidate" the "Onvalidate"-field is empty if i set another field of the same dataset in the OnValidate event.
I tryed to go back to 7.1.3. Same behaviour. Is there a version out who works?

azyk
Devart Team
Posts: 1057
Joined: Fri 11 Apr 2014 11:47
Location: Alpha Centauri A

Re: Random value assignement for fields with OnValidate event

Post by azyk » Wed 02 Sep 2015 13:40

This problem was detected after SDAC 7.1.6 release. Therefore, we didn't check whether it reproduced on earlier SDAC versions. This fix will be included in the next SDAC build.

Post Reply