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

16,320

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:
16,320
connorbp
Author by

connorbp

i like to tinker and toy around with web development and Delphi application development. i know php, html, and i am learning Delphi.

Updated on June 04, 2022

Comments

  • connorbp
    connorbp almost 2 years

    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.