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

六月ゝ 毕业季﹏ 提交于 2019-12-05 22:54:49

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.

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 :)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!