Inno Setup Set Uninstallable directive based on cu

2019-04-17 02:06发布

问题:

I want to know, how to use Uninstallable directive, when I don't have tasks or components:

[Setup]
Uninstallable:not if IscomponentSelected ('comp1 comp2')

I don't have tasks or components created. I only created some checkboxes with a "portable" option, which I want to add uninstallable option, when that one is checked:

[Code] 
var 
 Component: TWizardPage; 
 portable,installer: TNewRadioButton;
 Copmp: TLabel; 

function install: Boolean; 
begin 
  Result := installer.Checked; 
end; 

function portab: Boolean; 
begin 
  Result := portable.Checked; 
end; 

procedure InitializeWizard(); 
begin 
 Component :=
   CreateCustomPage(
     wpSelectDir, 'Component Selection',
     'Which types and components would you like to install?'); 

CompPanel := TPanel.Create(WizardForm); 
 with CompPanel do 
 begin 
   Parent := Component.Surface; 
   Left := ScaleX(0); 
   Top := ScaleY(0); 
   Width := ScaleX(417); 
   Height := ScaleY(100); 
   BevelOuter := bvNone; 
  end; 

Copmp := TLabel.Create(WizardForm); 
  with Copmp do 
  begin 
   Parent := CompPanel; 
   Caption := 'Type and components:'; 
   Left := ScaleX(0); 
   Top := ScaleY(5); 
   Width := ScaleX(150); 
   Height := ScaleY(13); 
 end; 

portable := TNewRadioButton.Create(WizardForm); 
 with portable do 
 begin 
   Parent := CompPanel; 
   Left := ScaleX(5); 
   Top := ScaleY(25); 
   Width := ScaleX(200); 
   Height := ScaleY(17); 
   Caption := 'Unpacking'; 
   OnClick:=@CopmpClick; 
 end; 

installer := 
TNewRadioButton.Create(WizardForm); 
 with installer do 
 begin 
   Parent := CompPanel; 
   Left := ScaleX(5); 
   Top := ScaleY(45); 
   Width := ScaleX(200); 
   Height := ScaleY(17); 
   Caption := 'Install'; 
   OnClick:=@CopmpClick; 
   Checked:=True; 
 end;

回答1:

Just implement a custom function:

function IsUninstallable: Boolean;
begin
  Result := installer.Checked;
end;

And use it in the Uninstallable directive:

[Setup]
Uninstallable=IsUninstallable