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

If and then statement not working 4

Status
Not open for further replies.

Mezzzo

Technical User
May 30, 2003
56
US
procedure TDoorMain.RadioButtonInsetClick(Sender: TObject);
begin
If RadioButtonInset.Checked = True and CboNumberOfDoors.items.indexof('1') then
begin
PanelSinInset.Visible := True;
end;
end.

The code is to allow the panel to visible if
a number in the combo is 1.
Please help. I get an error that the opertaor not applicable.
 
I don't think you need that begin in the if statement. I could be wrong. Since the end. is only needed once on the form, I think, it doesn't really relate to the first begin there. So you, in essence, have 2 begins and only one end;. I would try that, though there's a strong chance that I'm wrong...I'm pretty new at this.
 
Delphi doesn't always interpret complex statements the way you think it should. Use parentheses to make your intent clear:
[blue]
Code:
If  (RadioButtonInset.Checked = True) and (CboNumberOfDoors.items.indexof('1')>=0) then
[/color]

In this particular case, the "operator not applicable" is because the expression
Code:
    CboNumberOfDoors.items.indexof('1')
is not a boolean. (It is an integer.) Consequently, you cannot use it directly with if

 
Also, you don't have to use "= True" or "= False" when evaluating things that are supposed to give a boolean value. You could rewrite your If statement as:
[blue]
If RadioButtonInset.Checked and (CboNumberOfDoors.items.indexof('1')>=0) then
[/blue]

If you were looking for a false value, you'd do:
[blue]
If Not RadioButtonInset.Checked ...
[/blue]

-D
 
You could simplify this in to one statement:-

PanelSinInset.Visible := RadioButtonInset.Checked and (CboNumberOfDoors.items.indexof('1')>=0);

lou

 
Actually, shouldn't it be :-

PanelSinInset.Visible := RadioButtonInset.Checked and (CboNumberOfDoors.items[CboNumberOfDoors.itemIndex]='1');


 
Lou

Your code simplification is incorrect. It doesn't have the same effect as Mezzzo's original code.

Take for example the situation when PanelSinInset.Visible is already TRUE.

Now if RadioButtonInset.Checked is FALSE your code would set PanelsSinInset.Visible to FALSE but in Mezzzo's original code he would leave PanelSinInset.Visible as TRUE.





Andrew
Hampshire, UK
 
hi Andrew

You are right. I was just going off the textual bit "The code is to allow the panel to visible if a number in the combo is 1." so I assumed if it wasn't '1' then it wouldn't be visible.

lou

 
Lou,

Your interpetation of the "specification" may be correct but, on the other hand, there may be something else on the form such as a checkbox which, if checked, also requires the panel to be visible.

Without knowing this, it seems unwise to me, to change the meaning of Mezzzo's code without some kind of warning.



Andrew
Hampshire, UK
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top