views:

246

answers:

3

This is the code section from inno setup.My intention is to make two Checkbox where at a time one is being selected. But this code return error.

[code] section:

procedure CheckBoxOnClick(Sender: TObject);
var
Box2,CheckBox: TNewCheckBox;
begin
if CheckBox.Checked then
   CheckBox.State := cbUnchecked;
   Box2.State := cbChecked;
else                                //THIS LINE RETURNS AN ERROR: "Identifier Expected."
   CheckBox.State := cbChecked;
   Box2.State := cbUnchecked;
end;

procedure Box2OnClick(Sender: TObject);
var
Box2,CheckBox: TNewCheckBox;
begin
if Box2.Checked then
   CheckBox.State := cbChecked;
   Box2.State := cbUnchecked;
else                               //same error
   CheckBox.State := cbUnchecked;
   Box2.State := cbChecked;
end;

procedure CreateTheWizardPages;
var
  Page: TWizardPage;
  Box2,CheckBox: TNewCheckBox;
begin
  { TButton and others }

  Page := CreateCustomPage(wpWelcome, '', '');

  CheckBox := TNewCheckBox.Create(Page);
  CheckBox.Top :=ScaleY(8)+ScaleX(50);
  CheckBox.Width := Page.SurfaceWidth;
  CheckBox.Height := ScaleY(17);
  CheckBox.Caption := 'Do this';
  CheckBox.Checked := True;
  CheckBox.OnClick := @CheckBoxOnClick;
  CheckBox.Parent := Page.Surface;

  Box2 := TNewCheckBox.Create(Page);
  Box2.Top :=ScaleY(8)+ScaleX(70);
  Box2.Width := Page.SurfaceWidth;
  Box2.Height := ScaleY(17);
  Box2.Caption := 'No,Thanks.';
  Box2.Checked := False;
  Box2.OnClick := @Box2OnClick;
  Box2.Parent := Page.Surface;
end;


procedure InitializeWizard();
//var
begin
  { Custom wizard pages }
  CreateTheWizardPages;
end;

Please tell me where to change..

+1  A: 

In Pascal after then and else a single statement or a block must follow.

This is how the parser interprets your code:

  1. In case the condition is true, the line CheckBox.State := cbUnchecked; will be executed. With that statement the if clause is finished.
  2. Then Box2.State := cbChecked; will always be executed.
  3. The else does not belong to any currently open if statement -> Syntax error

You have to enclose the code in a block, like this:

procedure CheckBoxOnClick(Sender: TObject);
var
  Box2,CheckBox: TNewCheckBox;
begin
  if CheckBox.Checked then
  BEGIN
     CheckBox.State := cbUnchecked;
     Box2.State := cbChecked;
  END else                               
  BEGIN
     CheckBox.State := cbChecked;
     Box2.State := cbUnchecked;
  END;
end;
DR
Well my bad,Thanks.
neo-nant
A: 

very simple. Add a begin ... end clause after your then.


if CheckBox.Checked then
BEGIN
   CheckBox.State := cbUnchecked;
   Box2.State := cbChecked;
END
else                                
Etamar L.
A: 

Thanks friends.But it shows an error in run time when first checkbox is clicked.Like this:

Line 19: Could not call proc

http://i42.tinypic.com/sm81z9.jpg

line 19 is: if CheckBox.Checked then

What i would do then about it..?

neo-nant
You havent initialized that local CheckBox variable to anything. You should just use the [Tasks] section instead of trying to use [Code] if you're not familiar with Pascal (or familiarize yourself with it first).
mlaan
Yes i know that i have to use **Sender: TObject** for declearing local variable as CheckBox|Box2.But i dont know the syntax..I googled much for it and being failed i asked this as a new thread.So would you please help me figure it out..or tell how to..i am just tried coz i am with this for 3 days!
neo-nant
Use [Tasks] section.
mlaan