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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Comparison always evaluates to true. 1

Status
Not open for further replies.

pierrotsc

Programmer
Nov 25, 2007
358
US
I am getting this warning and this is the source code. why? I do not get it.
if (rgb.r >= 0) and (rgb.r <= 12) then
Statusbar.Panels[7].Text := 'Zone 0';

Next statement does not generate the error,:
if (rgb.r >= 13) and (rgb.r <= 38) then
Statusbar.Panels[7].Text := 'Zone I';

Thanks.
P
 
I just tried your code, and I do not get the same warning, but that's with the understanding that I don't know how you declared rgb.

How do you declare rgb, specifically r?
 
is rgb.r a 'byte' by any chance? So must be >= 0
or
If you comment out the statement where the warning occurs does it compile correctly, or move the warning down.

Steve: N.M.N.F.
If something is popular, it must be wrong: Mark Twain
 
yes rgb.r is a byte. It is the red value for the RGB pixel. The values are 0 to 255. By the way i get the same error when I have if rgb.r <= 255.
Any way around removing the warning.?
Thanks.
 
Try:

Code:
if (rgb.r <= 12) then
    Statusbar.Panels[7].Text := 'Zone 0'
else
    if (rgb.r <= 38) then
        Statusbar.Panels[7].Text := 'Zone I';

or

Code:
if (rgb.r in [0..12]) then
    Statusbar.Panels[7].Text := 'Zone 0';

if (rgb.r in [13..38]) then
    Statusbar.Panels[7].Text := 'Zone I';

I hope this helps.


Casas a venda em Suzano
 
Try using set ranges and see what happens.

Code:
if rgb.r in [0..12] then
   Statusbar.Panels[7].Text := 'Zone 0';

But somehow since my attempt at compiling the above didn't produce the warning, I have a feeling something else is going on in the structure of the code which is making it so this statement always evaluates to true.

It is not possible for anyone to acknowledge truth when their salary depends on them not doing it.
 
I get that warning!, Glenn did you define the fields as byte?
dinner ready but I will be back!


Steve: N.M.N.F.
If something is popular, it must be wrong: Mark Twain
 
Thanks guys, you help me find the issue...
If i just put if rgb.r<=12 and remove the rgb.r>=0 the error goes away.
same thing with if rgb.r>=242 and remove the rgb.r<=255

I now do not get the warnings...
Appreciate the troubleshooting.
P
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top