Checkbox

Simple really....(Getting old,so cant
remember simple things ....)
I have a checkbox and a button
(button1 and checkbox1).
Declared
Var checked :boolean;
for the form.
Then wrote on buttonclick:
IF checkbox1.checked := True THEN
application.terminate
ELSE
Showmessage('Whatever')
end;
Then I cant compile because compiler gives me error:
"Type of expression must be boolean"
What am I doing wrong?
srbenavrbeAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

wimmeyvaertCommented:
Hello,

The answer to your question is also simple :
In an IF-statement you can't use an assignment (:=). You have to make a comparison between 2 values (=, <>, >, <, ...).
Below the correct code :

IF checkbox1.checked = True THEN
  application.terminate
ELSE
  Showmessage('Whatever');


Or even Better :

IF checkbox1.checked THEN
  application.terminate
ELSE
  Showmessage('Whatever');


Hope your problem is solved now.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
IndefreiCommented:
You better use
If checkbox1.State:=cbchecked then
   // do whatever
else
   // blabla
regards
Indi
0
IndefreiCommented:
Oops, eliminate the >> : << , which has been the mistake before
0
srbenavrbeAuthor Commented:
Ohh ...I get it!
Just one more tiny Q (with points ofcourse)...
If I were to add another request to my
code,example:
IF checkbox1.checked = True THEN
  Showmessage('Whatever');
Mediaplayer1.Play
Else
......
What is the right syntax as (;) is
not alowed before ELSE ?

0
IndefreiCommented:
IF checkbox1.checked = True THEN
begin                    
   Showmessage('Whatever');
   Mediaplayer1.Play;
end
Else
begin
     .
     .
end;
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.