Page 1 of 1

dbCheckbox not updating - delphi

Posted: Tue 05 Jun 2018 13:20
by marsheng
I have a dbcheckbox and the changes are not being recorded. I can check and uncheck the box but nothing is stored.

In MySql I tried setting the type to Char(1), Bit, Int(1) and binary. Char and Binary do not cause Delphi to crash. In the fieldkind of Delphi, all MySql fields come through as fkData.

In the object inspector, Delphi seems to know what is TStringField and TIntegerField but there is no where to change this type.

Not sure how to go forward other than writing code.
Thanks Wallace.

Re: dbCheckbox not updating - delphi

Posted: Thu 07 Jun 2018 09:07
by ViktorV
To solve your task, you can use the system type tinyint(1). For example:

Code: Select all

BoolField tinyint(1)
When working with MySQL, UniDAC creates a TBooleanField for these fields.
Also you can use Data Type Mapping for fields of the system type Bit. Before connecting, you can set the following rule Data Type Mapping:

Code: Select all

MyConnection.DataTypeMap.AddDBTypeRule(myBit, ftBoolean);
This rule will be applied to the data of the system type Bit. To use constants myBit you need to add MyDataTypeMap unit in the uses section.
Also, you can map data of the system type Bit using the 'Field Name' of the needed columns:

Code: Select all

MyQuery.DataTypeMap.AddFieldNameRule(YourFieldName, ftBoolean);

Re: dbCheckbox not updating - delphi

Posted: Thu 07 Jun 2018 09:58
by marsheng
Thanks Viktor

tinyInt(1) worked and Delphi sees this as a Boolean field. Not sure why Delphi doesn't recognize an actual Boolean field.

Cheers Wallace.

Re: dbCheckbox not updating - delphi

Posted: Thu 07 Jun 2018 10:55
by ViktorV
It is good to see that the problem has been solved.
Feel free to contact us if you have any further questions about our products.