event-handlinginno-setuppascalscript

Access to custom control from OnClick event of another control in Inno Setup


I have next code for Inno Setup:

procedure CheckBoxClick(Sender: TObject);
begin
  // How to make BrowseButton visible from here?
end;

procedure CreateTheWizardPage;
var
  Page: TWizardPage;
  BrowseButton, FormButton: TNewButton;
  CheckBox: TNewCheckBox;
  Memo: TNewMemo;
begin
  Page := PageFromID(wpReady);      
  BrowseButton := TNewButton.Create(Page);
  CheckBox := TNewCheckBox.Create(Page); 
  CheckBox.OnClick := @CheckBoxClick;
end;

I'm wondering how can I access custom controllers on the wizard page from handler procedure for one of them?


Solution

  • You have to make the BrowseButton variable global and define it before the event handler:

    var
      BrowseButton: TButton;
    
    procedure CheckBoxClick(Sender: TObject);
    begin
      // Now you can use the BrowseButton here
    end;
    
    procedure CreateTheWizardPage;
    var
      Page: TWizardPage;
      FormButton: TNewButton;
      CheckBox: TNewCheckBox;
      Memo: TNewMemo;
    begin
      Page := PageFromID(wpReady);      
      BrowseButton := TNewButton.Create(Page);
      CheckBox := TNewCheckBox.Create(Page); 
      CheckBox.OnClick := @CheckBoxClick;
    end;
    

    Related question: Reading values from custom Inno Setup wizard pages without using global variables