0
votes

My component section:

[Components]           
  Name: "client"; Description: "Client"; Types: full default monitor; 
  Name: "server"; Description: "Server"; Types: full default server; 
    Name: "server/feature"; Description: "Optional feature";   
    Name: "server/Db"; Description: "Always supported server feature"; Types: full default server; Flags: fixed
      Name: "server/Db/latest"; Description: "Latest"; Types: full default server; Flags: exclusive       
      Name: "server/Db/2_10"; Description: "2.10"; Flags: exclusive 

I would like to have component server/Db that is always selected when its parent server is selected. I was able to acomplish it with fixed flag, but then I'm not able to select server/Db/2_10. If I tried to select second exclusive component, server/Db is unsellected altogether. I can only select server/Db/2_10 if server/Db isn't flaged as fixed, but then I'm able to unselect it.

Edit:
I added procedures like in Inno Setup: how to auto select a component if another component is selected?. Just changed ComponentsListCheckChanges procedure like this, (because I don't want to allow user to uncheck it):

procedure ComponentsListCheckChanges;
begin
  // No metter what you chceck/uncheck force component if needed.
  if WizardIsComponentSelected('server') then
  begin 
    WizardSelectComponents('server/Db');
  end
  else
  begin
    WizardSelectComponents('!server/Db');
  end
end;

I just found out, that If I try to uncheck server/Db, its checked back, that's good, but Type change to Custom even if it match other predefined type. Did I made some mistakes?


Old:
I also tried to mark it as Disabled in code. I was able to select both exclusive components, but not able to Uncheck component server anymore.

[code]
procedure CurPageChanged(CurPageID: Integer);
begin
  if CurPageID = wpSelectComponents then
      WizardForm.ComponentsList.ItemEnabled[3] := False;
end;

I'm able to create same behavior in component section as with code above by adding custom to Types list. I'm able to select both exclusive components, but can't uncheck server

[Components]           
  Name: "client"; Description: "Client"; Types: full default monitor; 
  Name: "server"; Description: "Server"; Types: full default server; 
    Name: "server/feature"; Description: "Optional feature";   
    Name: "server/Db"; Description: "Always supported server feature"; Types: full default server custom; Flags: fixed
      Name: "server/Db/latest"; Description: "Latest"; Types: full default server; Flags: exclusive       
      Name: "server/Db/2_10"; Description: "2.10"; Types: custom; Flags: exclusive 

Last thing that I tried was setting it to True in code if server is checked. I Tried using code from: https://stackoverflow.com/a/36989894/2416941 , it forced server/Db to behave like I wanted but, in dropdown menu above components, Selected Type stopped changing, It always showed as Default instalation and not Custom or any other type, so I don't think that's a valid solution.

How can I force server/Db to be always checked with server and able to choose one of server/Db's children, and still possible to uncheck server?
Or is there other way to group exclusive components?

1
This aproach stops Types from changing after checking/unchecking any components. It keeps last selected type, never changes to Custom or any other type that much selection.Tundy
I have edited the answer.Martin Prikryl
I didn't save that answer before, what did change that it now update type? I edited question and added my bersion of ComponentsListCheckChanges. I found out, that If I try to uncheck server/Db, its checked back, that's good, but Type change to Custom even if it match other predefined type. Did I made some mistakes? Should I bother with this last thing or copy my ComponentsListCheckChanges to answer and mark it done? If this last thing worked I think it would be perfect.Tundy
There's a link to any post revision history just below the post text -- stackoverflow.com/posts/47431511/revisionsMartin Prikryl

1 Answers

0
votes

I made it works corectly by editing answers for Inno Setup: how to auto select a component if another component is selected? but had to add ComponentsListClickCheckPrev(nil); to Update Type selection corectly after calling WizardSelectComponents.

[Code]
var
  TypesComboOnChangePrev: TNotifyEvent;
  ComponentsListClickCheckPrev: TNotifyEvent;

procedure ComponentsListCheckChanges;
begin
  { If Check status of components is different }
  { Update child's status with parent's status. }
  if WizardIsComponentSelected('server') <> WizardIsComponentSelected('server/Db') then
  begin
    if WizardIsComponentSelected('server') then { If checked parent }
    begin
      WizardSelectComponents('server/Db'); { Check component }
    end
      else
    begin
      WizardSelectComponents('!server/Db'); { Uncheck component }
    end;
    ComponentsListClickCheckPrev(nil); { Update Type selection after my edits }
  end;
end;

procedure ComponentsListClickCheck(Sender: TObject);
begin
  { First let Inno Setup update the components selection }
  ComponentsListClickCheckPrev(Sender);
  { And then check for changes }
  ComponentsListCheckChanges;
end;

procedure TypesComboOnChange(Sender: TObject);
begin
  { First let Inno Setup update the components selection }
  TypesComboOnChangePrev(Sender);
  { And then check for changes }
  ComponentsListCheckChanges;
end;

procedure InitializeWizard();
begin
  { The Inno Setup itself relies on the TypesCombo.OnChange and OnClickCheck. }
  { so we have to preserve their  handlers. }

  ComponentsListClickCheckPrev := WizardForm.ComponentsList.OnClickCheck;
  WizardForm.ComponentsList.OnClickCheck := @ComponentsListClickCheck;

  TypesComboOnChangePrev := WizardForm.TypesCombo.OnChange;
  WizardForm.TypesCombo.OnChange := @TypesComboOnChange;
end;