Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

delphi dbgrid boolean value, accept f fa fal fals false , how to accept more values?

I'm using mssql and Delphi 2009. When a form contains a dbgrid that is connected to boolean field, the values are displayed as True, or False. The Delphi dbgrid has the ability to translate

f
fa
fal
fals
false
t
tr
tru
true

to be true or false. I want to add values so it can accept other strings, and match them to true or false. Where could these values be added?

like image 455
none Avatar asked Feb 20 '13 13:02

none


2 Answers

This is the default behavior for TBooleanField.DisplayValues. Look at the db unit source:
db.TBooleanField.SetAsString and db.TBooleanField.SetDisplayValues.

If you set TField.DisplayValues := 'Yes;No'; for example: Y, Ye, Yes will represent True; N, No will represent False.

You cannot add more values to it. Unless you utilize OnSetText as suggested by the other answer, or use a TDbGrid.PickList.

Personally, I would use a CheckBox for Boolean field value representation on the TDBGrid.
There are plenty of examples out there on how to do that.

like image 156
kobik Avatar answered Sep 20 '22 11:09

kobik


You could write an OnSetText event for your boolean field, and interpret any given text as True or False.

like image 30
iMan Biglari Avatar answered Sep 16 '22 11:09

iMan Biglari