Bug in TWebDBCheckBox component. Do not assign unchecked value the first time.

Into TWebDBCheckBox component whose ValueChecked and ValueUnchecked properties are assigned to "Y" and "N," respectively,
when you insert a new row in the table and leave the TWebDBCheckBox unmodified, the value saved in the linked Field is a Blank space instead of ValueUnchecked.

Steps to reproduce the problem.

  • Create an empty application and save all the files.
  • Into the default main form, drop the next components.
    a TWebDBNavigator
    a TWebClientDataset
    a TWebDataSource
    a TWebDBCheckBox
    a TWebDBLabel.
  • Into the WebClientDataset component, create a Field of type WideString with a length of 1 character with the field name CHECK_VALUE.
  • In the WebDBCheckBox1 change the next properties:
    set ValueChecked = "Y" and ValueUnchecked = "N".
    And now, link the components in the next form.

Set DataSource property of WebDataSource1 to WebDataSource1 value.
The same change is needed for the TWebDBNavigator component.

Set the values DataSource and DataField of the components WebDBCheckBox1 and WebDBLabel1 to the next values: WebDataSource1 and CHECK_VALUE.

Finally, create the EventHandler for Event OnCreate in the form and insert the next line: WebClientDataSet1.Active := True;

Next is the code of the dfm file of the example:

object Form6: TForm6
  Width = 640
  Height = 480
  CSSLibrary = cssBootstrap
  ElementFont = efCSS
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -15
  Font.Name = 'Tahoma'
  Font.Style = []
  ParentFont = False
  OnCreate = WebFormCreate
  object WebDBLabel1: TWebDBLabel
    Left = 420
    Top = 132
    Width = 90
    Height = 18
    Caption = 'WebDBLabel1'
    ElementFont = efCSS
    HeightStyle = ssAuto
    HeightPercent = 100.000000000000000000
    WidthPercent = 100.000000000000000000
    DataField = 'CHECK_VALUE'
    DataSource = WebDataSource1
  object WebDBNavigator1: TWebDBNavigator
    Left = 160
    Top = 230
    Width = 330
    Height = 25
    DataSource = WebDataSource1
    Hints.Strings = (
  object WebDBCheckBox1: TWebDBCheckBox
    Left = 140
    Top = 130
    Width = 171
    Height = 22
    Caption = 'WebDBCheckBox1'
    ChildOrder = 3
    ElementClassName = 'custom-control custom-checkbox'
    ElementButtonClassName = 'custom-control-input'
    ElementLabelClassName = 'custom-control-label'
    ElementFont = efCSS
    HeightStyle = ssAuto
    HeightPercent = 100.000000000000000000
    WidthPercent = 100.000000000000000000
    DataField = 'CHECK_VALUE'
    DataSource = WebDataSource1
    ValueChecked = 'Y'
    ValueUnChecked = 'N'
  object WebClientDataSet1: TWebClientDataSet
    Active = True
    Params = <>
    Left = 230
    Top = 270
    object WebClientDataSet1CHECK_VALUE: TWideStringField
      FieldName = 'CHECK_VALUE'
      Size = 1
  object WebDataSource1: TWebDataSource
    DataSet = WebClientDataSet1
    Left = 360
    Top = 270

Next is the code of the pas file of the example.

unit Unit6;


  System.SysUtils, System.Classes, JS, Web, WEBLib.Graphics, WEBLib.Controls,
  WEBLib.Forms, WEBLib.Dialogs, Vcl.Controls, WEBLib.DBCtrls, Data.DB, WEBLib.DB, WEBLib.CDS, Vcl.StdCtrls, WEBLib.StdCtrls;

  TForm6 = class(TWebForm)
    WebDBNavigator1: TWebDBNavigator;
    WebClientDataSet1: TWebClientDataSet;
    WebClientDataSet1CHECK_VALUE: TWideStringField;
    WebDataSource1: TWebDataSource;
    WebDBCheckBox1: TWebDBCheckBox;
    WebDBLabel1: TWebDBLabel;
    procedure WebFormCreate(Sender: TObject);
    { Private declarations }
    { Public declarations }

  Form6: TForm6;


{$R *.dfm}

procedure TForm6.WebFormCreate(Sender: TObject);
   WebClientDataSet1.Active := True;


How do we check the problem? Easy.

With the navigator, create a new row by pressing the + sign.
And immediately post it. You can see that the WebDBLabel1 component shows nothing.

Now you can edit the row and click on the WebDBCheckBox component, now if you left it active and post you can see in WebDBLabel1 an "Y" and if you repeat the steps but lefting it unchecked, you can see an "N".

The problem is that the first time must show an "N," and it left the value blank.

The workaround is to implement the EventHandler for the Event AfterInsert in the dataset and initialize the value of the CHECK_VALUE field to "N".

Thanks for reading it!

Normally you could set the default value in dataset.BeforeInsert but we applied an improvement to have this happening automatically. Next update will have this improvement.