1

I'm having problems with the About button in the components page. It works fine in the first page, when it is smaller but it looks like this (see the following screenshot) in this part.

enter image description here

The code is this one:

    [Setup]
    AppName=My Program
    AppVersion=1.5
    DefaultDirName={pf}\My Program
    DefaultGroupName=My Program
    UninstallDisplayIcon={app}\MyProg.exe
    OutputDir=userdocs:Inno Setup Examples Output


    [Types]
    Name: "full"; Description: "Full installation"
    Name: "compact"; Description: "Compact installation"
    Name: "custom"; Description: "Custom installation"; Flags: iscustom

    [Components]
    Name: "program"; Description: "Program Files"; Types: full compact custom; Flags: fixed
    Name: "help"; Description: "Help File"; Types: full
    Name: "readme"; Description: "Readme File"; Types: full
    Name: "readme\en"; Description: "English"; Flags: exclusive
    Name: "readme\de"; Description: "German"; Flags: exclusive

    [Code]
    procedure AboutButtonOnClick(Sender: TObject);
    begin
      MsgBox('This is a demo of how to create a button!', mbInformation, mb_Ok);
    end;

    procedure CreateAboutButton(ParentForm: TSetupForm; CancelButton: TNewButton);
    var
      AboutButton: TNewButton;
    begin
      AboutButton := TNewButton.Create(ParentForm);
      AboutButton.Left := ParentForm.ClientWidth - CancelButton.Left - CancelButton.Width;
      AboutButton.Top := CancelButton.Top;
      AboutButton.Width := CancelButton.Width;
      AboutButton.Height := CancelButton.Height;
      AboutButton.Caption := '&About...';
      AboutButton.OnClick := @AboutButtonOnClick;
      AboutButton.Parent := ParentForm;
    end;


    procedure InitializeWizard1();
    begin
      CreateAboutButton(WizardForm, WizardForm.CancelButton);
    end;

    type
      TPositionStorage = array of Integer;

    var
      CompPageModified: Boolean;
      CompPagePositions: TPositionStorage;

    procedure SaveComponentsPage(out Storage: TPositionStorage);
    begin
      SetArrayLength(Storage, 10);

      Storage[0] := WizardForm.Height;
      Storage[1] := WizardForm.NextButton.Top;
      Storage[2] := WizardForm.BackButton.Top;
      Storage[3] := WizardForm.CancelButton.Top;
      Storage[4] := WizardForm.ComponentsList.Height;
      Storage[5] := WizardForm.OuterNotebook.Height;
      Storage[6] := WizardForm.InnerNotebook.Height;
      Storage[7] := WizardForm.Bevel.Top;
      Storage[8] := WizardForm.BeveledLabel.Top;
      Storage[9] := WizardForm.ComponentsDiskSpaceLabel.Top;
    end;

    procedure LoadComponentsPage(const Storage: TPositionStorage;
      HeightOffset: Integer);
    begin
      if GetArrayLength(Storage) <> 10 then
        RaiseException('Invalid storage array length.');

      WizardForm.Height := Storage[0] + HeightOffset;
      WizardForm.NextButton.Top := Storage[1] + HeightOffset;
      WizardForm.BackButton.Top := Storage[2] + HeightOffset;
      WizardForm.CancelButton.Top := Storage[3] + HeightOffset;
      WizardForm.ComponentsList.Height := Storage[4] + HeightOffset;
      WizardForm.OuterNotebook.Height := Storage[5] + HeightOffset;
      WizardForm.InnerNotebook.Height := Storage[6] + HeightOffset;
      WizardForm.Bevel.Top := Storage[7] + HeightOffset;
      WizardForm.BeveledLabel.Top := Storage[8] + HeightOffset;
      WizardForm.ComponentsDiskSpaceLabel.Top := Storage[9] + HeightOffset;
    end;

    procedure InitializeWizard2();
    begin
      CompPageModified := False;
    end;

    procedure CurPageChanged(CurPageID: Integer);
    begin
      if CurpageID = wpSelectComponents then
      begin
        SaveComponentsPage(CompPagePositions);
        LoadComponentsPage(CompPagePositions, 200);
        CompPageModified := True;
      end
      else
      if CompPageModified then
      begin
        LoadComponentsPage(CompPagePositions, 0);
        CompPageModified := False;
      end;
    end;

       procedure InitializeWizard();
       begin 
        InitializeWizard1();
        InitializeWizard2();
       end;

Could anyone help me? Thanks so much in advanced.

Sertac Akyuz
  • 54,131
  • 4
  • 102
  • 169
DeXon
  • 419
  • 4
  • 12

2 Answers2

1

Due to a lack of missing Anchors property you will have to move that button by yourself when the form is being resized. So, what you can do in your script is publish the button instance and extend an existing position storage of the vertical position of your button. In code it may look like this:

[Setup]
AppName=My Program
AppVersion=1.5
DefaultDirName={pf}\My Program
DefaultGroupName=My Program
UninstallDisplayIcon={app}\MyProg.exe
OutputDir=userdocs:Inno Setup Examples Output

[Types]
Name: "full"; Description: "Full installation"
Name: "compact"; Description: "Compact installation"
Name: "custom"; Description: "Custom installation"; Flags: iscustom

[Components]
Name: "program"; Description: "Program Files"; Types: full compact custom; Flags: fixed
Name: "help"; Description: "Help File"; Types: full
Name: "readme"; Description: "Readme File"; Types: full
Name: "readme\en"; Description: "English"; Flags: exclusive
Name: "readme\de"; Description: "German"; Flags: exclusive

[Code]
type
  TPositionStorage = array of Integer;

var
  AboutButton: TNewButton;
  CompPageModified: Boolean;
  CompPagePositions: TPositionStorage;

procedure AboutButtonOnClick(Sender: TObject);
begin
  MsgBox('This is a demo of how to create a button!', mbInformation, mb_Ok);
end;

function CreateAboutButton(ParentForm: TSetupForm; CancelButton: TNewButton): TNewButton;
begin
  Result := TNewButton.Create(ParentForm);
  Result.Left := ParentForm.ClientWidth - CancelButton.Left - CancelButton.Width;
  Result.Top := CancelButton.Top;
  Result.Width := CancelButton.Width;
  Result.Height := CancelButton.Height;
  Result.Caption := '&About...';
  Result.OnClick := @AboutButtonOnClick;
  Result.Parent := ParentForm;
end;

procedure SaveComponentsPage(out Storage: TPositionStorage);
begin
  SetArrayLength(Storage, 11);

  Storage[0] := AboutButton.Top;
  Storage[1] := WizardForm.Height;
  Storage[2] := WizardForm.NextButton.Top;
  Storage[3] := WizardForm.BackButton.Top;
  Storage[4] := WizardForm.CancelButton.Top;
  Storage[5] := WizardForm.ComponentsList.Height;
  Storage[6] := WizardForm.OuterNotebook.Height;
  Storage[7] := WizardForm.InnerNotebook.Height;
  Storage[8] := WizardForm.Bevel.Top;
  Storage[9] := WizardForm.BeveledLabel.Top;
  Storage[10] := WizardForm.ComponentsDiskSpaceLabel.Top;  
end;

procedure LoadComponentsPage(const Storage: TPositionStorage;
  HeightOffset: Integer);
begin
  if GetArrayLength(Storage) <> 11 then
    RaiseException('Invalid storage array length.');

  AboutButton.Top := Storage[0] + HeightOffset;
  WizardForm.Height := Storage[1] + HeightOffset;
  WizardForm.NextButton.Top := Storage[2] + HeightOffset;
  WizardForm.BackButton.Top := Storage[3] + HeightOffset;
  WizardForm.CancelButton.Top := Storage[4] + HeightOffset;
  WizardForm.ComponentsList.Height := Storage[5] + HeightOffset;
  WizardForm.OuterNotebook.Height := Storage[6] + HeightOffset;
  WizardForm.InnerNotebook.Height := Storage[7] + HeightOffset;
  WizardForm.Bevel.Top := Storage[8] + HeightOffset;
  WizardForm.BeveledLabel.Top := Storage[9] + HeightOffset;
  WizardForm.ComponentsDiskSpaceLabel.Top := Storage[10] + HeightOffset;  
end;

procedure CurPageChanged(CurPageID: Integer);
begin
  if CurpageID = wpSelectComponents then
  begin
    SaveComponentsPage(CompPagePositions);
    LoadComponentsPage(CompPagePositions, 200);
    CompPageModified := True;
  end
  else
  if CompPageModified then
  begin
    LoadComponentsPage(CompPagePositions, 0);
    CompPageModified := False;
  end;
end;

procedure InitializeWizard();
begin 
  CompPageModified := False;
  AboutButton := CreateAboutButton(WizardForm, WizardForm.CancelButton);
end;
TLama
  • 75,147
  • 17
  • 214
  • 392
0

In my case I put an about button in the same row as the back and next and cancel buttons. In this way it does not matter if a page is resized. The code looks as:

 // Create an About button
 AboutButton := TButton.Create(WizardForm);
 with AboutButton do
  begin
   Parent   := WizardForm;
   Left     := WizardForm.ClientWidth - CancelButton.Left - CommonWidth;
   Top      := CancelButton.Top;
   Width    := CommonWidth;
   Height   := CommonHeight;
   Caption  := ExpandConstant('{cm:About}');
   OnClick  := @HelpButtonClick;
   ShowHint := True;
   Hint     := ExpandConstant('{cm:AboutHint}');
   Name     := 'AboutButton';
  end;

In the initialize setup routine I put the lines:

CommonWidth           := ScaleX(75); // Standard width for new buttons
CommonHeight          := ScaleY(23); // Standard heigth for new buttons
  • The button was *"in the same row"* as Next and Cancel buttons. Just when the OP resized the wizard form, the button's vertical position remained as it was due to a missing vertical anchor. This code would suffer from the same. You can try to change the wizard form's height to see it. Besides, I urge you to not use those magical constant values claiming they are default. The default width and height for a button you'll get if you won't explicitly change its size. – TLama Feb 26 '14 at 16:32