user6423048
user6423048

Reputation:

How do I create a checkbox on Ready page

I created a code which plays a slideshow or plays a background video when installing my program using Inno Setup. But I want to add a checkbox to the Background Option selection wizard page (CurPageID=wpReady) that can disable the background video/slideshow from playing.

When the Checkbox I prefer to add is checked, I want it to stop playing background slideshow or video and only to show the installing progress page (CurPageID=wpInstalling).

I wrote this but the compiler keeps saying

Line 1053, Column 3, Identifier Expected

The script I wrote:

var
NoBackgroundCheckBox: TNewCheckBox;

procedure NoBackgroundCheckBoxClick(Sender: TObject);
begin
  if NoBackgroundCheckBox.Checked then
  begin
    with WizardForm do
  begin
    FWAdd:=False
  end else begin
    with WizardForm do
  begin
    FWAdd:=True
    end;
  end;

with NoBackgroundCheckBox do
  begin
    Name := 'NoBackgroundCheckBox';
    Parent := WizardForm;
    Left := ScaleX(560);
    Top := ScaleY(115);
    Width := ScaleX(90);
    Height := ScaleY(14);
    Alignment := taLeftJustify;
    Caption := 'No Background Option';
    OnClick := @NoBackgroundCheckBoxClick;
  end;
  NoBackgroundCheckBox.TabOrder := 3;
end;

Thanks in advance.

Upvotes: 1

Views: 667

Answers (1)

Martin Prikryl
Martin Prikryl

Reputation: 202642

Create the checkbox in the InitializeWizard. And test its state in the NextButtonClick(wpReady), to decide if to start the playback or not. Alternatively you can also use CurStepChanged(ssInstall).

var
  NoBackgroundCheckBox: TNewCheckBox;

procedure InitializeWizard();
begin
  { shrink the "Ready" memo to make room for the checkbox }
  WizardForm.ReadyMemo.Height := WizardForm.ReadyMemo.Height - ScaleY(24);

  { create the checkbox }
  NoBackgroundCheckBox := TNewCheckBox.Create(WizardForm);
  with NoBackgroundCheckBox do
  begin
    Parent := WizardForm.ReadyMemo.Parent;
    Left := WizardForm.ReadyMemo.Left;
    Top := WizardForm.ReadyMemo.Top + WizardForm.ReadyMemo.Height + ScaleY(8);
    Height := ScaleY(Height);
    Width := WizardForm.ReadyMemo.Width;
    Caption := 'No Background Option';
  end;
end;

function NextButtonClick(CurPageID: Integer): Boolean;
begin
  { Next button was just clicked on the "Ready" page }
  if CurPageID = wpReady then
  begin
    { is the checkbox checked? }
    if NoBackgroundCheckBox.Checked then
    begin
      Log('NoBackgroundCheckBox is checked, won''t play anything');
    end
      else
    begin
      { the checkbox is not checked, here call your function to start the playback }
      Log('NoBackgroundCheckBox is not checked, will play');
    end;
  end;

  Result := True;
end;

enter image description here

Upvotes: 1

Related Questions