Search code examples
installationinno-setuppascalscript

Multi-line edit in Inno Setup on page created by CreateInputQueryPage


By default, when you add a TEdit to a page in Inno Setup, the height is one line.

How do I increase the height of the edit?

Here is the relevant part of the ISS file

ContractConfigPage := CreateInputQueryPage(ServerConfigPage.ID,
  'Map contract as JSON', 'Please enter the map contract to use in JSON format', '');    
ContractConfigPage.Add('JSON', False);
ContractConfigPage.Edits[0].Height := 100; { does not have any effect }

Edit: I am now able to have a bigger edit but I can not have multiple lines

ContractConfigPage := CreateInputQueryPage(ServerConfigPage.ID,
  'Map contract as JSON', 'Please enter the map contract to use in JSON format', '');    
ContractConfigPage.Add('JSON', False);
ContractConfigPage.Edits[0].AutoSize := False;
ContractConfigPage.Edits[0].Height := 100;
ContractConfigPage.Edits[0].Width := 100;
{ now the edit is bigger but I still can not have multiple lines }

Solution

  • You have to replace the TPasswordEdit with TNewMemo:

    var
      JsonMemo: TNewMemo;
    
    procedure InitializeWizard();
    var
      ContractConfigPage: TInputQueryWizardPage;
      JsonIndex: Integer;
      JsonEdit: TCustomEdit;
    begin
      { Create new page }
      ContractConfigPage := CreateInputQueryPage(wpWelcome,
        'Map contract as JSON', 'Please enter the map contract to use in JSON format', '');    
    
      { Add TPasswordEdit. We use it only to have Inno Setup create the prompt label and }
      { to calculate the proper location of the edit control }
      JsonIndex := ContractConfigPage.Add('JSON', False);
      JsonEdit := ContractConfigPage.Edits[JsonIndex];
    
      { Create TNewMemo (multi line edit) on the same parent control and }
      { the same location (except for height) as the original single-line TPasswordEdit }
      JsonMemo := TNewMemo.Create(WizardForm);
      JsonMemo.Parent := JsonEdit.Parent;
      JsonMemo.SetBounds(JsonEdit.Left, JsonEdit.Top, JsonEdit.Width, ScaleY(100));
    
      { Hide the original single-line edit }
      JsonEdit.Visible := False;
    
      { Link the label to the new edit }
      { (has a practical effect only if there were a keyboard accelerator on the label) }
      ContractConfigPage.PromptLabels[JsonIndex].FocusControl := JsonMemo;
    end;
    

    Now you cannot use ContractConfigPage.Edits to access the TNewMemo and its value (it references the original [hidden] TPasswordEdit). You have to use the global JsonMemo variable.


    You can of course create the page completely yourself, starting from a clean page using CreateCustomPage. It might be a cleaner solution, but more laborious.