connorbp
connorbp

Reputation: 327

Delphi if else if else statement not working "Type of expression must be BOOLEAN"

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.

Upvotes: 3

Views: 17298

Answers (1)

RRUZ
RRUZ

Reputation: 136391

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...');

Upvotes: 14

Related Questions