Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I am trying to make a currency converter in Delphi, and it has been a while since i last used Delphi so i am a bit rusty. When i am trying to make an if, else if, else statement it is giving me the error: "Type of expression must be BOOLEAN".

Here is my code:

if Edit1.Text = '' And Edit2.Text <> ''
    then Edit2.Text := '1'
else
if Edit1.Text <> '' And Edit2.Text = ''
    then ShowMessage('Blah')
else
if Edit1.Text ='' And Edit2.Text = ''
    then ShowMessage('Please Enter A Value')
else
    ShowMessage('Mathing Suff...');

If anyone can see my dumb mistakes or what is going wrong that would help a lot. :)

EDIT: the errors are popping up on the line of the first if statement and the two else if's after it.

share|improve this question
add comment

1 Answer

up vote 12 down vote accepted

This is because the operator precedence, you should put each condition in parentheses

Try this code

if (Edit1.Text = '') And (Edit2.Text <> '')  then 
  Edit2.Text := '1'
else 
if (Edit1.Text <> '') And (Edit2.Text = '') then 
  ShowMessage('Blah')
else 
if (Edit1.Text ='') And (Edit2.Text = '')then 
  ShowMessage('Please Enter A Value')
else 
  ShowMessage('Mathing Suff...');
share|improve this answer
 
That worked :) (Except one of the brackets contained and else if. But i fixed it) –  connorbp Jun 12 '13 at 0:18
 
Thanks. Its funny how simple it was. –  connorbp Jun 12 '13 at 0:18
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.