1

I want to modify the parameters of a FileName in the [Run] section according to the state of some radio and check buttons. In my code section I have added:

function GetParameterString:String;
var
  I: Integer;
  s1, s2: String;
begin
  for I := 0 to WizardForm.RunList.Items.Count - 1 do
    if (wizardform.runlist.items.checked[i] = true) then begin
      if (wizardform.runlist.items.itemcaption[i] = 'View Whats''s New in ' + {#MyAppVersion}) then       
        s1 := GetShellFolderByCSIDL(CSIDL_APPDATA, True) + '\Positron Studio\What''s New.pdf';
      if (wizardform.runlist.items.itemcaption[i] = 'Positron Studio Dark' then
        s2 := '-d'
      else if (wizardform.runlist.Items.itemcaption[i] = 'Positron Studio Light' then
        s2 := '-l'
    end;
  end;
  Result := s1 + s2
end;

and I am calling it from the [Run] section like this:

FileName:"{app}\{#MyAppExename}"; parameters: Code: GetParameterString; \
    Flags: postinstall nowait

It fails on the wizardform.runlist.items.checked[i] = true with:

Unknown Identifier Checked

How do I get the Checked value of a checkbox or radiobutton?

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
John Barrat
  • 810
  • 4
  • 15

2 Answers2

1

Lookup Pascal Scripting: Scripted Constants where it states:

The Pascal script can contain several functions which are called when Setup wants to know the value of a scripted {code:...} constant. The called function must have 1 String parameter named Param, and must return a String or a Boolean value depending on where the constant is used.

So try:

FileName: "{app}\{#MyAppExename}"; Parameters: {code:GetParameterString}; Flags: postinstall nowait

The above has not been tested. It may not fix the underlaying issue with what you are actually doing in the GetParameterString method.

Andrew Truckle
  • 17,769
  • 16
  • 66
  • 164
  • The compile fails because the Checked state is not recognised. I am obviously not accessing the controls correctly so I need guidance on that. My routine returns a string so as far as I can see there is not a problem in the FileName entry in the [run] section – John Barrat Apr 18 '21 at 07:13
  • Thank you that was very helpful. Is possible for the preprocessor defines to be used by the code section? and is it possible to tell if an item in the runlist is radiobutton or Checkbutton? – John Barrat Apr 18 '21 at 07:45
  • 1
    @JohnBarrat No, you cannot tell if an item of `TNewCheckListBox` is radio button or a checkbox. The list defined by the `Run` section cannot even contain radio buttons. If you have hacked it somehow in the code, you know the indexes of the checkboxes and radio buttons anyway, don't you? – Martin Prikryl Apr 18 '21 at 09:47
  • I think my best approach would be to replace the normal run page with a custom page. It has other benefits in doing this as I can add images images. – John Barrat Apr 18 '21 at 12:53
  • @JohnBarrat Sure. But the whole point of StackOverflow is that if people take the time to supply you answers and you find them useful that you "upvote" them. – Andrew Truckle Apr 18 '21 at 15:11
1

Your immediate problem is that there's indeed no wizardform.runlist.items.checked (nor wizardform.runlist.items.itemcaption).

You want WizardForm.RunList.Checked (and WizardForm.RunList.ItemCaption).

See the TNewCheckListBox documentation.


Your next problem will be the invalid syntax of the reference to your scripted constant in the Parameters parameter (as Andrew has already shown in his answer). It should be:

Parameters: {code:GetParameterString}; 

Your next problem will be "Invalid prototype":
"Identifier Expected" or "Invalid Prototype" when implementing a scripted constant in Inno Setup

It should be:

function GetParameterString(Param: string): string;

Depending on how you application handles the argument, you also might need to the path to the .pdf, as there are spaces in it.

It also bit strange, how you add the -d and -l to the path. Did you really intend to pass something like this to the application?

C:\Users\user\AppData\Roaming\Positron Studio\What's New.pdf-d

It also bit unclear to me, how are you combining multiple "run list" entries states into arguments of one particular entry. But I assume you know what you are doing.

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992