user10980670
user10980670

Reputation:

Illegal expression: if, then, else statement

I don't understand what's wrong with this code:

procedure WebBrowserForm.CheckBox1Click(Sender: TObject);
begin
  if CheckBox1.Checked = true then
    Button1.Enabled = true else
    Button1.Enabled = false;
end;

Could somebody please tell me?

Upvotes: 1

Views: 211

Answers (1)

MartynA
MartynA

Reputation: 30715

Your code should be

procedure WebBrowserForm.CheckBox1Click(Sender: TObject);
begin
  if CheckBox1.Checked = true then
    Button1.Enabled := true else
    Button1.Enabled := false;
end;

In Delphi, the assignment operator is :=, while = is the comparison operator instead.

BTW, you could write your code more simply as

procedure WebBrowserForm.CheckBox1Click(Sender: TObject);
begin
  Button1.Enabled := CheckBox1.Checked;
end;

Upvotes: 9

Related Questions