6

My application requires .NET Framework to be installed so I run .NET installation in PrepareToIntall event function. While the installation is running I would like to display some simple message on Wizard.

I found How to set the status message in [Code] Section of Inno install script? but the solution there doesn't work for me.

I tried

WizardForm.StatusLabel.Caption := CustomMessage('InstallingDotNetMsg');

and also

WizardForm.PreparingLabel.Caption := CustomMessage('InstallingDotNetMsg');

EDIT

I have to do this in PrepareToInstall function, because I need to stop the setup when .net installation fails.

Code looks like this right now:

function PrepareToInstall(var NeedsRestart: Boolean): String;
var 
   isDotNetInstalled : Boolean;
   errorCode : Integer;
   errorDesc : String;
begin
   isDotNetInstalled := IsDotNetIntalledCheck();
   if not isDotNetInstalled then 
   begin
      //WizardForm.PreparingLabel.Caption := CustomMessage('InstallingDotNetMsg');
      WizardForm.StatusLabel.Caption := CustomMessage('InstallingDotNetMsg');
      ExtractTemporaryFile('dotNetFx40_Full_x86_x64.exe');
      if  not ShellExec('',ExpandConstant('{tmp}\dotNetFx40_Full_x86_x64.exe'),'/passive /norestart', '', SW_HIDE, ewWaitUntilTerminated, errorCode) then
      begin
        errorDesc := SysErrorMessage(errorCode);
        MsgBox(errorDesc, mbError, MB_OK);
      end; 
      isDotNetInstalled := WasDotNetInstallationSuccessful();
      if not isDotNetInstalled then
      begin
         Result := CustomMessage('FailedToInstalldotNetMsg');
      end;
   end;
end;

Any Ideas how to achieve this?

Community
  • 1
  • 1
Kapitán Mlíko
  • 4,498
  • 3
  • 43
  • 60
  • 2
    [`Would you mind having a progress marquee`](http://stackoverflow.com/a/20753218/960757) :-) ? – TLama May 13 '14 at 12:45
  • TLama is right. Installing via [Run] section is best solution in most cases. You should install 3rd party apps before `wpInstalling` only if such an app is used during `wpInstalling` for some reason. – RobeN May 13 '14 at 12:50
  • @TLama +1 on your solution. unfortunately I think I cannot use this solution, because I would like to abort setup when .Net framework installation fails. That's why I use PrepareToInstall function. I will update my question to show you my code. – Kapitán Mlíko May 13 '14 at 13:33

2 Answers2

14

The StatusLabel is hosted by the InstallingPage wizard page while you're on PreparingPage page in the PrepareToInstall event method. So that's a wrong label. Your attempt to set the text to the PreparingLabel was correct, but failed because that label is hidden by default (it is shown when you return non empty string as a result to the event method).

But you can show it for a while (you are using ewWaitUntilTerminated flag, so your installation is synchronous, thus it won't hurt anything):

[Code]
function PrepareToInstall(var NeedsRestart: Boolean): String;
var
  WasVisible: Boolean;
begin
  // store the original visibility state
  WasVisible := WizardForm.PreparingLabel.Visible;
  try
    // show the PreparingLabel
    WizardForm.PreparingLabel.Visible := True;
    // set a label caption
    WizardForm.PreparingLabel.Caption := CustomMessage('InstallingDotNetMsg');
    // do your installation here
  finally
    // restore the original visibility state
    WizardForm.PreparingLabel.Visible := WasVisible;
  end;
end;
TLama
  • 75,147
  • 17
  • 214
  • 392
  • I just made simple script where I tested various methods since you suggested Refresh procedure. I found Show procedure and it works... when you do `WizardForm.PreparingLabel.Show()` then it's exactly it. And better when you do `WizardForm.StatusLabel.Show();` you get also that progressBar. This solution works as well. So I accept it :) Btw I am from CR too :)) – Kapitán Mlíko May 13 '14 at 14:20
  • Wait, but you must be on the next page to see the `StatusLabel` or `ProgressGauge`. You're on the `PreparingPage` when the `PrepareToInstall` event is fired. [I've noticed that :-) Nice art on some of your projects!] – TLama May 13 '14 at 14:29
  • Well I don't know what you mean. I tried and it works... is there any problem I can cause by being on different page and calling StatusLabel.Show()? It seems to be working well. – Kapitán Mlíko May 13 '14 at 14:32
  • It shouldn't work. Those controls are physically on a different page. And you shouldn't be on that page. That's crazy :-) Which version of Inno Setup do you use ? And is it ANSI or Unicode ? – TLama May 13 '14 at 14:34
  • maybe Show procedure switches those pages. I use Inno Setup version 5.5.3 and script is UTF-8 if that's what you ask. – Kapitán Mlíko May 13 '14 at 14:39
  • 1
    D'oh, I forgot that [`Show`](http://docwiki.embarcadero.com/Libraries/XE5/en/Vcl.Controls.TControl.Show) method (in Delphi) ensures that the parent is visible, so it brings the page to front, and it "turns" it only visually. Well, you should avoid doing that, even though in this case you're quite lucky, since e.g. when restart will be required, the setup switches back to the `PreparingPage`, so it seems to behave as required. – TLama May 13 '14 at 15:11
0

Another solution is to use CreateOutputProgressPage to display a progress page over the top of the Preparing to Install page. See the CodeDlg.iss example script included with Inno for an example of the usage; it's fairly straightforward.

Miral
  • 12,637
  • 4
  • 53
  • 93