Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Changing font color on button IF... 3

Status
Not open for further replies.

Jonah86

Programmer
Dec 11, 2003
152
US
I need a way to change the font color on a button at runtime if certain conditions are met. The point is, whenever a particular field in a db is not blank then make the button stand out so that the user knows that there is something there to look at.

I tried it like this:

IF query.fieldbyname('comment').asString <> '' THEN
button1.font.color := clYellow;

or something to that extent. It didn't come close to working. One problem I seem to have is, even at design time, I can't make the button font color change. So what I did was try and substitute the color = yellow for size = 4 so I could at least see if the IF statement was working...it didn't seem to be, as nothing changed.

I'm using Delphi 7, and BDE.
 
Wow, that's a lot of code just to change the button font color...but that IS what I asked for. So thank you again for all of your help:)

Now, do you think that the IF structure I'm using is acurate or does that need altered as well?
 
You could use a TBitBtn instead and just set it's font.color property.

 
Wow, ok, yeah...that works. Thank you so much. Let me try out the IF thing and see if life just got better:)

Thank you.
 
About your IF, it may be that the field is null

Try something like

IF not (query.fieldbyname('comment').isNull) then
if (query.fieldbyname('comment').asString <> '') THEN
MyBitBtn.font.color := clyellow;


If you remove the <>'' condition and just have the isNull bit then isNull will be false if the field value contains ''.

lou

 
The original IF condition is fine and complete.

If a string field is null, the asString parameter will return '' without error, so the &quot;not.....isNull&quot; check is superfluous.

Simon


 
Yeah, the IF worked fine once I was informed about the bit buttons. Thanks a lot all!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top