tags:

views:

163

answers:

1

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 when first checkbox is clicked.

[code]

procedure CheckBoxOnClick(Sender: TObject);
var
Box2,CheckBox: TNewCheckBox;
begin
if CheckBox.Checked then   ///error:"Could not call proc" [sud it be global if then how to or what to change?]
BEGIN
   CheckBox.State := cbUnchecked;
   Box2.State := cbChecked;
END else
BEGIN
   CheckBox.State := cbChecked;
   Box2.State := cbUnchecked;
END;
end;

procedure Box2OnClick(Sender: TObject);
var
Box2,CheckBox: TNewCheckBox;
begin
if Box2.Checked then              ///error:same
BEGIN
   CheckBox.State := cbChecked;
   Box2.State := cbUnchecked;
END else
BEGIN
   CheckBox.State := cbUnchecked;
   Box2.State := cbChecked;
END;
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..

A: 

The cause of your error is that your are referencing CheckBox which is defined locally in that method. At this point CheckBox has not been created. Which means your calling CheckBox.Checked when CheckBox is undefined (most likely NIL)

Each declaration of CheckBox represents a new variable and does not reference the other variables with the same name. This is due to scoping rules.

One option to solve your problem is to remove the local declarations of Box2, and CheckBox in each method and declare them globally.

Robert Love