在 CreateInputQueryPage 创建的页面上的 Inno Setup 中进行多行编辑
Multi-line edit in Inno Setup on page created by CreateInputQueryPage
默认情况下,当您在 Inno Setup 中向页面添加 TEdit
时,高度为一行。
如何增加编辑的高度?
这是 ISS 文件的相关部分
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 }
编辑:我现在可以进行更大的编辑,但不能有多行
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 }
您必须将 TPasswordEdit
替换为 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;
现在您不能使用 ContractConfigPage.Edits
访问 TNewMemo
及其值(它引用原始 [hidden] TPasswordEdit
)。您必须使用全局 JsonMemo
变量。
您当然可以完全自己创建页面,使用 CreateCustomPage
从干净的页面开始。这可能是一个更简洁的解决方案,但更费力。
这是我最终使用的代码:
var
ContractConfigPage: TWizardPage;
ContractMemo: TNewMemo;
然后在 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+
'}';
请注意,在 JSON 中,我使用 '' 而不是 ",因为该值将进入 xml,因此更易于阅读:)
默认情况下,当您在 Inno Setup 中向页面添加 TEdit
时,高度为一行。
如何增加编辑的高度?
这是 ISS 文件的相关部分
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 }
编辑:我现在可以进行更大的编辑,但不能有多行
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 }
您必须将 TPasswordEdit
替换为 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;
现在您不能使用 ContractConfigPage.Edits
访问 TNewMemo
及其值(它引用原始 [hidden] TPasswordEdit
)。您必须使用全局 JsonMemo
变量。
您当然可以完全自己创建页面,使用 CreateCustomPage
从干净的页面开始。这可能是一个更简洁的解决方案,但更费力。
这是我最终使用的代码:
var
ContractConfigPage: TWizardPage;
ContractMemo: TNewMemo;
然后在 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+
'}';
请注意,在 JSON 中,我使用 '' 而不是 ",因为该值将进入 xml,因此更易于阅读:)