Recent

Author Topic: [SOLVED] Conversion problem  (Read 1151 times)

Zvoni

  • Hero Member
  • *****
  • Posts: 2319
Re: [SOLVED] Conversion problem
« Reply #15 on: April 27, 2023, 11:06:44 am »
In MySQL the field returned is 'NULL'. I use:
Code: Pascal  [Select][+][-]
  1.     // Change text color if null field
  2.     if sText = 'NULL' then StringGrid1.Canvas.Font.Color := clSilver
  3.     else                           StringGrid1.Canvas.Font.Color := clBlack;
  4. ...
  5.  
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
Code: SQL  [Select][+][-]
  1. Vers1 (ANSI-SQL): SELECT SomeID, CASE WHEN SomeField IS NULL THEN 0 ELSE 1 END AS SomeColorIndex FROM SomeTable
  2. Vers2 (MySQL-Specific): SELECT SomeID, IF(ISNULL(SomeField),0,1) AS SomeColorIndex FROM SomeTable

and then in code along these lines (untested)
Code: Pascal  [Select][+][-]
  1. Var
  2.   MyColor:Array[0..1] Of TColor=(clSilver, clBlack);
  3. .
  4. .
  5. //Execute Query to retrieve the values
  6. StringGrid1.Canvas.Font.Color := MyColor[SomeDataSet.FieldByName['SomeColorIndex'].AsInteger];
« Last Edit: April 27, 2023, 11:40:10 am by Zvoni »
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

jcmontherock

  • Full Member
  • ***
  • Posts: 234
Re: [SOLVED] Conversion problem
« Reply #16 on: April 27, 2023, 11:40:49 am »
Yes, sorry, you are right...
I forgot that in result of my query I tested if the field returned is nil before I gave it the value 'NULL'.
Windows 11 UTF8-64 - Lazarus 3.2-64 - FPC 3.2.2

Zvoni

  • Hero Member
  • *****
  • Posts: 2319
Re: [SOLVED] Conversion problem
« Reply #17 on: April 27, 2023, 11:41:43 am »
Yes, sorry, you are right...
I forgot that in result of my query I tested if the field returned is nil before I gave it the value 'NULL'.
And as written above: completely unneccessary
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

Slyde

  • Full Member
  • ***
  • Posts: 152
Re: [SOLVED] Conversion problem
« Reply #18 on: April 27, 2023, 01:57:36 pm »
Hey wp.  This is the way I'd normally do it, like you showed here in your reply:

Code: Pascal  [Select][+][-]
  1. Memo5.Text := frmMain.DS2.DataSet.Fields[5].AsString;

But everything's not normal right now  :D   Twisted my knee last week and doc gave me some pain killers that really really work.  The trade-off is a LOT of cloudy thinking though. 

I appreciate everyone's input on this.  Excellent forum!
Linux Mint 21.3
Lazarus 3.0

Zvoni

  • Hero Member
  • *****
  • Posts: 2319
Re: [SOLVED] Conversion problem
« Reply #19 on: April 27, 2023, 02:46:37 pm »
The trade-off is a LOT of cloudy thinking though. 
Then lean back and enjoy...

btw:... do you share?  :D :D
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

Slyde

  • Full Member
  • ***
  • Posts: 152
Re: [SOLVED] Conversion problem
« Reply #20 on: April 27, 2023, 02:54:40 pm »
 :D
Linux Mint 21.3
Lazarus 3.0

 

TinyPortal © 2005-2018