Search code examples
inno-setuppascalscript

Inno Setup Place controls on wpPreparing Page


I am trying to place a label on the wpPreparing page to indicate uninstallation of an existing version, prior to running the new installation. Here is my code:

function PrepareToInstall(var NeedsRestart: Boolean): String;
var
  UninstallingLabel: TNewStaticText;
  intResultCode: Integer;
begin
  with UninstallingLabel do
    begin
      Caption := 'Uninstalling existing version...';
      Left := WizardForm.StatusLabel.Left;
      Top := WizardForm.StatusLabel.Top;
      Parent := wpPreparing.Surface;
    end;
  if strExistingInstallPath <> '' then
    begin
      Exec(GetUninstallString, '/verysilent /suppressmsgboxes', '', SW_HIDE,
        ewWaitUntilTerminated, intResultCode);
    end;
end;

The trouble is it does not seem to like Parent := wpPreparing.Surface and compiling fails with a

Semicolon (;) expected

error. This syntax works when adding a label to a custom created page. Why does this fail when trying to add it to wpPreparing?


Solution

  • The wpPreparing is not an object, it's just a numerical constant.

    The WizardForm.PreparingPage holds a reference to the "Preparing to Install" page. Note that it is of type TNewNotebookPage already, not TWizardPage. So you use it directly as a parent.


    Also note that the StatusLabel is on the "Installing" page. You probably want to relate your new label to the PreparingLabel instead.


    And you have to create the UninstallingLabel.


    UninstallingLabel := TNewStaticText.Create(WizardForm);
    
    with UninstallingLabel do
    begin
      Caption := 'Uninstalling existing version...';
      Left := WizardForm.PreparingLabel.Left;
      Top := WizardForm.PreparingLabel.Top;
      Parent := WizardForm.PreparingPage;
    end;
    

    Though do you really want to shadow the PreparingLabel (as you use its coordinates).

    What about reusing it instead?

    WizardForm.PreparingLabel.Caption := 'Uninstalling existing version...';