The absence of evident support of boolean fields in InterBase always surprised and interested the developers who used this server. And in any case these developers had to emulate the support of boolean fields.

Here it is necessary to mention that this emulation is possible only in client applications. It is so because the server itself is a determinate thing and any programmer cannot change it separately. That is why the question arises: what is the best way of emulation of boolean fields in applications?

In practice there are two usual solutions. You create either the first or second following domains:

CREATE DOMAIN T_BOOLEAN_INT
AS SMALLINT
DEFAULT 0
NOT NULL
CHECK (VALUE IN (0,1))

Or

CREATE DOMAIN T_BOOLEAN_CHAR
AS CHAR(1)
DEFAULT 'F'
NOT NULL
CHECK (VALUE IN ('T', 'F'))

Fields created with these domains are considered by the developer to be Boolean and with the help of visual components are shown to users. In particular if using TDBCheckBox you can show such properties as ValueChecked := 'T' and ValueUnchecked := 'F'. In this case the component will behave as if it deals with a real boolean field.

It is more difficult to allow users to edit some boolean fields in components of the TDBGrid type simply by ticking off instead of evident setting the 'F' property. Such way of programming will require non-trivial steps.

Of course you probably have thought a lot about the easiest way of solving this problem. If while executing the query Delphi automatically creates TBooleanField instances for necessary fields, the programmer's life will become more comfortable!

This possibility has already been realized in FIBPlus. For this in the database it is necessary to describe some domain like the above-mentioned 'T_BOOLEAN_INT'. That is the domain should necessarily be either of the smallint or integer type, which allows two possible values "0" and "not 0" and contains the word "boolean" in its name. Then you enable the corresponding option in TpFIBDataSet, for example:

pFIBDataSet1.PrepareOptions := pFIBDataSet1.PrepareOptions + [psUseBooleanField] (this can be done both in design-time and in run-time)

After this all the fields created with our special domain will be considered to be boolean and for them there will be automatically created TFIBBooleanField instances (it is a direct descendant of the TBooleanField class). That means that any visual component will consider the fields to be real boolean fields and this is very important for normal work!


Preview text: The absence of evident support of boolean fields in InterBase always surprised and interested the developers who used this server. And in any case these developers had to emulate the support of boolean fields.
Prices in Euro:

235 (1 copy)
1250 (unlimited)

Volume discounts are available...

Navigation



"FIBPlus is a great choice if you're going to work with InterBase and/or Firebird. The components let you easily use all the features of both databases in your applications...FIBPlus will make your InterBase and Firebird development easier than ever before...". Read the full story. >>

Bill Todd, president of The Database Group, Inc., a contributing editor to Delphi Informant Magazine, and a member of Team B
FOR CUSTOMERS
Download full versions and updates in your Personal Area