« Reply #15 on: April 27, 2023, 11:06:44 am »
In MySQL the field returned is 'NULL'. I use:
// Change text color if null field
if sText = 'NULL' then StringGrid1.Canvas.Font.Color := clSilver
else StringGrid1.Canvas.Font.Color := clBlack;
...
That's not a NULL-Value.
It's a text 'NULL'
btw: COALESCE works in MySQL, too.
EDIT: This looks like a "Boolean" scenario.
First, i'd change the Query to return 1 or 0 (Integer-values)
Something like
Vers1 (ANSI-SQL): SELECT SomeID, CASE WHEN SomeField IS NULL THEN 0 ELSE 1 END AS SomeColorIndex FROM SomeTable
Vers2 (MySQL-Specific): SELECT SomeID, IF(ISNULL(SomeField),0,1) AS SomeColorIndex FROM SomeTable
and then in code along these lines (untested)
Var
MyColor:Array[0..1] Of TColor=(clSilver, clBlack);
.
.
//Execute Query to retrieve the values
StringGrid1.Canvas.Font.Color := MyColor[SomeDataSet.FieldByName['SomeColorIndex'].AsInteger];
« Last Edit: April 27, 2023, 11:40:10 am by Zvoni »
Logged
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad