DBInspectorBar with "fake" Boolean Fields

Hi !

Could you please make 2 tiny changes in DBInspectorBar.pas, so we'll be able to use integer fields as Boolean fields (1=True, 0=False) with the ptBoolean PropertyType and take benefit of the inspector checkboxes feature without implementing customized & weird methods/events?

Currently, when PropertyType = ptBoolean it only works well if the field is a TBooleanField, but it's not always a choice. And the DataLink methods only check the datafield kind, not the PropertyType of the TDBInspectorItem.

I could achieve it with 2 simple changes in methods DataChange & DataUpdate:

procedure TDBInspectorItem.DataChange(Sender: TObject);
   ...
   ...
begin
   ...
   ...
    case FDataLink.Field.DataType of
    ftSmallInt,ftInteger,ftWord:
      begin
        { new check }
        if PropertyType = ptBoolean then begin
          BoolValue := (FDataLink.Field.AsInteger <> 0);
        end else begin
          { just as it was before }
          IntValue := FDataLink.Field.AsInteger;
          TextValue := FDataLink.Field.DisplayText;
        end;
      end;
procedure TDBInspectorItem.DataUpdate(Sender: TObject);
begin
   ...
   ...
    case FDataLink.Field.DataType of
    ftSmallInt,ftInteger,ftWord:
      { new check }
      if PropertyType = ptBoolean then begin
        { didn't use "IfThen" because I didn't want to change the "uses" clause }
        if BoolValue then
          FDataLink.Field.AsInteger := 1
        else
          FDataLink.Field.AsInteger := 0;
      end else
        { as before }
        FDataLink.Field.AsInteger := IntValue;

Could you please take into consideration adding these changes?

Thanks.

We will investigate this, but as an alternative, have you considered using a calculated (boolean) field?

It could work, but not very practical with legacy DBs with no Boolean datatype, and gets worse when there are many 0/1s settings fields that would require manually cloning them, manually setting their values in AfterScroll, and then manually setting back the values to real fields in BeforePost.

For databases that implement Boolean type as a short for an tiny integer or bit field, Delphi will map it to TIntegerField instead of TBooleanField. MySQL,SQLite,etc. Not even SQL Server or Oracle implement a native Boolean type.

It would be great to have properties like "ValueTrue" & "ValueFalse" (& maybe ValueNull) as Variant to serve both fake integer/character Boolean fields. I believe many applications still run on DBs with 0/1s or 'Y'/'N' fake Boolean fields.

Understood, it would be easier. We'll consider it for a future update.

1 Like