1

I need to create an installer with Inno Setup (version 6.2.1) in which I need to let the user select which file extension he want to associate with the installed app.

To achieve that I needed to create a custom page showing all the checkboxes I needed. This page respects a custom theme required by my company, for that reason I could not use the checkboxes automatically generated by the [Tasks] section.

However I cannot figure out how to associate the checkbox state with the registry key I want to install (or not).

For example, I have the following code:

[Code]
var
  AssocABCCB: TNewCheckBox;

  ...

  procedure InitializeWizard;
  var
    SelectAssocPage: TWizardPage;
  begin
    // select association custom page
    SelectAssocPage := CreateCustomPage(wpLicense, ExpandConstant('{cm:SelectAssocTitle}'), '');

    ...

    // .abc checkbox
    AssocABCCB         := TNewCheckBox.Create(SelectAssocPage);
    AssocABCCB.Align   := alTop;
    AssocABCCB.Caption := ExpandConstant('{cm:AssocABC}');
    AssocABCCB.Parent  := SelectAssocPage.Surface;
    AssocABCCB.OnClick := @AssocABCCBClick;

    ...

  end;

Now I want to use the above checkbox to optionally write a key in the registry, let say something like that:

[Registry]
Root: HKCR; Subkey: "{#KeyAppName}.abc"; Flags: uninsdeletekeyifempty; Check: AssocABCCB.Checked

Of course the above code is not working, it raises a compilation error.

But is there a way to bind the above checkbox with the registry key, in order to determine if the key may be written or not? If yes, how may I achieve that?

Jean-Milost Reymond
  • 1,833
  • 1
  • 15
  • 36
  • @MartinPrikryl unfortunately this solution doesn't work in my case. As I briefly mentioned (at least I tried to) in my above description, the "Check:" keyword located in the [Registry] section doesn't find nothing coming from my [Code] section, either a component name nor even a function name. This is NOT the case in the [Files] section, which is the proposed solution in your above post. But I need to check something in the [Registry], not in the [Files]. – Jean-Milost Reymond May 04 '22 at 16:18
  • 1
    You cannot access a variable in the `Check` parameter directly. You have to wrap it to a function, as [my answer](https://stackoverflow.com/q/45003721/850848#45004225) shows. It does not matter if it is a `[Files]` or `[Registry]` section. – Martin Prikryl May 04 '22 at 17:44

1 Answers1

1

So I finally found what was the issue.

In fact it was an if statement was not closed correctly in one of my functions. This forced the following end statement to be closed with a . instead of a ;

Here was my wrong code:

[Code]

...

procedure CurStepChanged(CurStep: TSetupStep);
begin
  Log('CurStepChanged(' + IntToStr(Ord(CurStep)) + ') called');
  if CurStep = ssPostInstall then
    FinishedInstall := True;
  end; // <= here was the issue
end.

function DoAssocABC: Boolean;
begin
  Result := AssocABCCB.Checked;   
end;

...

[Registry]
Root: HKCR; Subkey: "{#KeyAppName}.abc"; Flags: uninsdeletekeyifempty; Check: DoAssocABC

Because my function was located AFTER the dotted end, it WAS NOT VISIBLE from ANY other statements, for that reason my [Registry] statement didn't find the function I tried to bind.

Unfortunately the compiler didn't complain about that. I don't know if it's a bug from Inno Setup itself.

Correcting that, the Martin Prikryl comment became right, and this fixed my issue:

You cannot access a variable in the Check parameter directly. You have to wrap it to a function, as my answer shows. It does not matter if it is a [Files] or [Registry] section. – Martin Prikryl

Jean-Milost Reymond
  • 1,833
  • 1
  • 15
  • 36