Christophe Blin
Christophe Blin

Reputation: 1909

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 }

Upvotes: 3

Views: 1726

Answers (2)

Martin Prikryl
Martin Prikryl

Reputation: 202594

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.

Upvotes: 4

Christophe Blin
Christophe Blin

Reputation: 1909

Here is the code I finally use for my need :

var
ContractConfigPage: TWizardPage;
ContractMemo: TNewMemo;

Then in the InitializeWizard :

ContractConfigPage := CreateCustomPage(ServerConfigPage.ID,
  'Map contract as JSON', 'Please enter the map contract to use in JSON format WITHOUT DOUBLE QUOTES');    
ContractMemo := TNewMemo.Create(WizardForm);
ContractMemo.Parent := ContractConfigPage.Surface;
ContractMemo.SetBounds(0, 0, 410, 210);
ContractMemo.ScrollBars := ssBoth;
ContractMemo.WordWrap := False;
ContractMemo.Text := '{'+#13#10+
'  name:''map'''+#13#10+
'}';

Please not that inside the JSON I use '' instead of " because the value will go into xml so this is easier to read :)

Upvotes: 3

Related Questions