Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

use of **and** operator within an **if statement**

I was directed to this website by a friend.

I am trying to use and in Delphi, but I seem to be doing something wrong. Is there something you need to put in uses?

I have the following code:

procedure TForm1.Button1Click(Sender: TObject);
var
a,b:string;
begin
a:=edit1.Text;
b:=edit2.Text;

if a=abc and b=def then
showmessage(a+b);

end;

I get an error at the second = sign

like image 916
gerard Avatar asked Mar 30 '11 15:03

gerard


1 Answers

You have to put some parentheses to change the operator precedence:

  if (a=abc) and (b=def) then

Operator and precedes = so the construction without parenthesis is understood as a=(abc and b=def) which produces the syntax error.

like image 97
PA. Avatar answered Sep 28 '22 13:09

PA.