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.

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..

I'm not familiar with TWizardPage or TNewCheckBox classes but it seems to me that Box2 and Checkbox are both local variables in each of the functions/procedures.
As such they are uninitialized under CheckBoxOnClick when you try to use them.
You might try to find the correct object using Sender ( The parameter Sender is the the checkbox that was clicked, so it's owner or parent will be the page and using that page's methods/objects you should be able to find the correct TNewCheckbox to uncheck ). Something like:
TWizardPage(TNewCheckBox(Sender).owner).<some method or function to find the correct control under it>
Or use Radiobutton that automatically allows only one to be selected.

Hi,

I see that in both then and else sections you have two statements and there are not enclosed in begin..end.
Change your code as in the following example:

procedure CheckBoxOnClick(Sender: TObject);
var
Box2,CheckBox: TNewCheckBox;
begin
if CheckBox.Checked then
 begin
   CheckBox.State := cbUnchecked;
   Box2.State := cbChecked;
 end //no semicolon before else
else            
    begin
        CheckBox.State := cbChecked;
        Box2.State := cbUnchecked;
    end;
end;

Ionut

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.