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

StackOverflow https://stackoverflow.com/questions/14981221

  •  10-03-2022
  •  | 
  •  

Вопрос

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?

Это было полезно?

Решение

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.

Другие советы

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

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top