Inno Setup: создание пользовательской формы - PullRequest
1 голос
/ 27 февраля 2020

Я работаю с Inno Setup. Я новичок, и я не очень знаком с этим. В моем стандартном установщике есть две страницы, одна за другой, элементы которых мне нужно использовать (RepositoryPage и ServicePage (последняя страница)).

RepositoryPage:

enter image description here

procedure CreateRepositoryPage;
var
    i : Integer;
    SqlNamesArray: TArrayOfString;
    LblMonitorService, LblUsername, LblPassword : TNewStaticText;
begin

    RepositoryPage := CreateInputQueryPage(wpSelectComponents, 'Configuration', '' , '');

    { Windows username. RepositoryPage.Edits[2] }
    RepositoryPage.Add('', False);
    { Windows password. RepositoryPage.Edits[3] }
    RepositoryPage.Add('', True);

    LblMonitorService := TNewStaticText.Create(RepositoryPage);
    with LblMonitorService do
    begin
        Parent := RepositoryPage.Surface;
        Left := 0;
        Width := RepositoryPage.SurfaceWidth;
        Height := ScaleY(17);
        AutoSize := False;
        Caption := 'Dashboard service';
    end;

    LblUsername := TNewStaticText.Create(RepositoryPage);
    with LblUsername do
    begin
        Parent := RepositoryPage.Surface;
        Left := 0;
        Top := LblMonitorService.Top + LblMonitorService.Height + ScaleY(17);
        Width := RepositoryPage.SurfaceWidth;
        Height := ScaleY(17);
        AutoSize := False;
        Caption := 'Windows account username (Domain\Username):';
    end;

    RepositoryPage.Edits[0].Top := LblUsername.Top + LblUsername.Height;

    LblPassword := TNewStaticText.Create(RepositoryPage);
    with LblPassword do
    begin
        Parent := RepositoryPage.Surface;
        Left := 0;
        Top := RepositoryPage.Edits[0].Top + RepositoryPage.Edits[0].Height + ScaleY(15);
        Width := RepositoryPage.SurfaceWidth;
        Height := ScaleY(17);
        AutoSize := False;
        Caption := 'Windows account password:';
    end;

    RepositoryPage.Edits[1].Top := LblPassword.Top + LblPassword.Height;


    LogOnAsServiceCheckBox := TNewCheckBox.Create(RepositoryPage);
    with LogOnAsServiceCheckBox do
    begin
        Parent := RepositoryPage.Surface;
        Top := RepositoryPage.Edits[1].Top + RepositoryPage.Edits[1].Height + ScaleY(16);
        Left := 0;
        Width := RepositoryPage.SurfaceWidth;
        Height := ScaleY(17);
        Caption := 'Add "Log on as a service" permission';
        Checked := True;
    end;


    RepositoryPage.Values[0] := ExpandConstant('{computername}') + '\' + ExpandConstant('{username}');
    RepositoryPage.Values[1] := '';

    { Change text color for textboxes }
    RepositoryPage.Edits[1].Font.Color := $ffffff;

end;

ServicePage:

enter image description here

[Code]
procedure CreateServicePage;
var
    SSLNameArray : TArrayOfString;
    i : Integer;
begin

    ServicePage := CreateInputQueryPage(RepositoryPage.ID, 'Web server configuration',  '' , '');

    { Username. ServicePage.Edits[0] }
    ServicePage.Add('', False);
    { Password. ServicePage.Edits[1] }
    ServicePage.Add('', True);
    { Confirm Password. ServicePage.Edits[2] }
    ServicePage.Add('', True);

    { Http server configuration }

    {   Http checkbox  }
    HttpServerOptionCheckBox := TNewCheckBox.Create(ServicePage);
    with HttpServerOptionCheckBox do
    begin
        Parent := ServicePage.Surface;
        Top := ScaleY(0);
        Left := 0;
        Width := ScaleX(350);
        Caption := 'HTTP web server';
        Checked := True;
        OnClick := @OnHttpServerOptionCheckBox;
    end;

    {   Label for Http port }
    LblHttpPort := TNewStaticText.Create(ServicePage);
    with LblHttpPort do
    begin
        Parent := ServicePage.Surface;
        Left := ScaleX(15);
        Top := HttpServerOptionCheckBox.Top + HttpServerOptionCheckBox.Height + ScaleY(5);
        Width := ServicePage.SurfaceWidth;
        AutoSize := False;
        TabOrder := 1;
        Caption := 'Server port:';
    end;

    {   Edit for Http port }
    HttpPortTextBox := TNewEdit.Create(ServicePage);
    with HttpPortTextBox do
    begin
        Parent := ServicePage.Surface;
        Top := LblHttpPort.Top + LblHttpPort.Height + ScaleY(2);
        Left := ScaleX(15);
        Width := ScaleX(60);
        Text := '5019';
        Font.Color := $ffffff;
    end;

    {   Test button for testing Http port }
    TestHttpPortButton := TNewButton.Create(ServicePage);
    with TestHttpPortButton do
    begin
        Parent := ServicePage.Surface;
        Top := HttpPortTextBox.Top - ScaleY(2);
        Left := HttpPortTextBox.Width + ScaleX(20);
        Width := ScaleX(75);
        Height := ScaleY(23);
        OnClick := @TestHttpPortButtonOnClick;
        Caption := 'Test';
    end;

    { Checkbox for Http port firewall exception }
    CreateAddFirewallexceptionHttpCheckBox := TNewCheckBox.Create(ServicePage);
    with CreateAddFirewallexceptionHttpCheckBox do
    begin
        Parent := ServicePage.Surface;
        Top := HttpPortTextBox.Top + HttpPortTextBox.Height + ScaleY(5);
        Left := ScaleX(15);
        Width := ScaleX(350);
        Height := ScaleY(17);
        Caption := 'Create a firewall exception for the specified port';
        Checked := True;
    end;

    { //////////////////////////////////////////////////////////////////////////////////// }

    { Https server checkbox  }
    HttpsServerOptionCheckBox := TNewCheckBox.Create(ServicePage);
    with HttpsServerOptionCheckBox do
    begin
        Parent := ServicePage.Surface;
        Top := CreateAddFirewallexceptionHttpCheckBox.Top + CreateAddFirewallexceptionHttpCheckBox.Height + ScaleY(20);
        Left := 0;
        Width := ScaleX(120);
        Height := ScaleY(17);
        Caption := 'HTTPS web server';
        Checked := False;
        OnClick := @OnHttpsServerOptionCheckBox;
    end;

    { Https server port label    }
    LblHttpsPort := TNewStaticText.Create(ServicePage);
    with LblHttpsPort do
    begin
        Parent := ServicePage.Surface;
        Left := ScaleX(15);
        Top := HttpsServerOptionCheckBox.Top + HttpsServerOptionCheckBox.Height + ScaleY(2);
        Width := ScaleX(60);
        Height := ScaleY(17);
        AutoSize := False;
        Caption := 'Server port: ';
    end;

    { Https server port edit     }
    HttpsPortTextBox := TNewEdit.Create(ServicePage);
    with HttpsPortTextBox do
    begin
        Parent := ServicePage.Surface;
        Top := LblHttpsPort.Top + LblHttpsPort.Height;
        Left := LblHttpsPort.Left;
        Width := ScaleX(60);
        Height := ScaleY(17);
        Text := '4443';
        Font.Color := $ffffff;
    end;

    { Https server site name label  }
    LblSiteName := TNewStaticText.Create(ServicePage);
    with LblSiteName do
    begin
        Parent := ServicePage.Surface;
        Left := HttpsPortTextBox.Left + HttpsPortTextBox.Width +    ScaleX(10);
        Top := HttpsServerOptionCheckBox.Top + HttpsServerOptionCheckBox.Height + ScaleY(2);
        Width := ScaleX(98);
        Height := ScaleY(17);
        AutoSize := False;
        Caption := 'Host name or IP:';
    end;

    { Https server site name edit }
    HttpsSiteNameTextBox := TNewEdit.Create(ServicePage);
    with HttpsSiteNameTextBox do
    begin
        Parent := ServicePage.Surface;
        Top := LblSiteName.Top + LblSiteName.Height;
        Left := LblSiteName.Left;
        Width := ScaleX(140);
        Height := ScaleY(17);
        Text := '';
        Font.Color := $ffffff;
    end;

    LblSSLName := TNewStaticText.Create(ServicePage);
    with LblSSLName do
    begin
        Parent := ServicePage.Surface;
        Left := HttpsSiteNameTextBox.Left + HttpsSiteNameTextBox.Width + ScaleX(10) ;
        Top := HttpsServerOptionCheckBox.Top + HttpsServerOptionCheckBox.Height + ScaleY(2);
        Width := ScaleX(50);
        Height := ScaleY(17);
        AutoSize := False;
        Caption := 'SSL: ';
    end;

    SSLComboBox := TNewComboBox.Create(RepositoryPage);
    with SSLComboBox do
    begin
        Parent := ServicePage.Surface;
        Style := csDropDown;
        Left := LblSSLName.Left;
        Top := LblSSLName.Top + LblSSLName.Height;
        Width := ScaleX(150);
        Height := ScaleY(17);
        ItemIndex := 0;
    end;

    if not (IsAppUpgrade or IsSameVersion) then begin
         SSLNameArray := GetSSLCertificates();
         for i:= 0 to GetArrayLength(SSLNameArray)-1 do begin
                SSLComboBox.Items.Add(SSLNameArray[i])
         end;
    end;

        {   Test button for testing Https port }
    TestHttpsPortButton := TNewButton.Create(ServicePage);
    with TestHttpsPortButton do
    begin
        Parent := ServicePage.Surface;
        Top := SSLComboBox.Top - ScaleY(2);
        Left := SSLComboBox.Left + SSLComboBox.Width + ScaleX(5);
        Width := ScaleX(75);
        Height := ScaleY(23);
        OnClick := @TestHttpsPortButtonOnClick;
        Caption := 'Test';
    end;

    CreateAddFirewallexceptionHttpsCheckBox := TNewCheckBox.Create(ServicePage);
    with CreateAddFirewallexceptionHttpsCheckBox do
    begin
        Parent := ServicePage.Surface;
        Top := HttpsSiteNameTextBox.Top + HttpsSiteNameTextBox.Height + ScaleY(5);
        Left := ScaleX(15);
        Width := ScaleX(350);
        Height := ScaleY(17);
        Caption := 'Create a firewall exception for the specified port';
        Checked := True;
    end;

    { User managment }
    LblServicePageUser := TNewStaticText.Create(ServicePage);
    with LblServicePageUser do
    begin
        Parent := ServicePage.Surface;
        Top := CreateAddFirewallexceptionHttpsCheckBox.Top + CreateAddFirewallexceptionHttpsCheckBox.Height + ScaleY(15);
        Left := 0;
        Width := ServicePage.SurfaceWidth;
        Height := ScaleY(0);
        AutoSize := False;
        Caption := 'Application user';
    end;

    LblServicePageUsername := TNewStaticText.Create(ServicePage);
    with LblServicePageUsername do
    begin
        Parent := ServicePage.Surface;
        Left := 0;
        Top := LblServicePageUser.Top + LblServicePageUser.Height + ScaleY(5);
        Width := ServicePage.SurfaceWidth;
        Height := ScaleY(17);
        AutoSize := False;
        Caption := 'Application username: ';
    end;

    ServicePage.Values[0] := strMonitorUser;
    ServicePage.Edits[0].Top := LblServicePageUsername.Top + LblServicePageUsername.Height;

    LblServicePagePassword := TNewStaticText.Create(ServicePage);
    with LblServicePagePassword do
    begin
        Parent := ServicePage.Surface;
        Left := 0;
        Top := ServicePage.Edits[0].Top + ServicePage.Edits[0].Height + ScaleY(5);
        Width := ServicePage.SurfaceWidth;
        Height := ScaleY(17);
        AutoSize := False;
        Caption := 'New password: ';
    end;

    ServicePage.Edits[1].Top := LblServicePagePassword.Top + LblServicePagePassword.Height;

    LblServicePageConfirmPassword := TNewStaticText.Create(ServicePage);
    with LblServicePageConfirmPassword do
    begin
        Parent := ServicePage.Surface;
        Left := 0;
        Top := ServicePage.Edits[1].Top + ServicePage.Edits[1].Height + ScaleY(2);
        Width := ServicePage.SurfaceWidth;
        Height := ScaleY(17);
        AutoSize := False;
        Caption := 'Confirm password: ';
    end;

    ServicePage.Edits[2].Top := LblServicePageConfirmPassword.Top + LblServicePageConfirmPassword.Height;

    EnableServicePageElements;

    { Change text color for textboxes }
    ServicePage.Edits[0].Font.Color := $ffffff;
    ServicePage.Edits[1].Font.Color := $ffffff;
    ServicePage.Edits[2].Font.Color := $ffffff;

    OnHttpServerOptionCheckBox( HttpServerOptionCheckBox);
    OnHttpsServerOptionCheckBox( HttpsServerOptionCheckBox);

end;

ConfigForm содержит все элементы из ServicePage и RepositoryPage, он используется только для создания файла конфигурации (который будет использоваться позже), а также отдельно от установщика (не имеют страниц до и после). Как я могу сделать заказ ConfigForm, показанный на картинке ниже?

enter image description here

Ответы [ 2 ]

1 голос
/ 28 февраля 2020

Проверьте пример использования CreateCustomForm функции в CodeClasses.iss файла примера :

procedure FormButtonOnClick(Sender: TObject);
var
  Form: TSetupForm;
  Edit: TNewEdit;
  OKButton, CancelButton: TNewButton;
begin
  Form := CreateCustomForm();
  try
    Form.ClientWidth := ScaleX(256);
    Form.ClientHeight := ScaleY(128);
    Form.Caption := 'TSetupForm';

    Edit := TNewEdit.Create(Form);
    Edit.Top := ScaleY(10);
    Edit.Left := ScaleX(10);
    Edit.Width := Form.ClientWidth - ScaleX(2 * 10);
    Edit.Height := ScaleY(23);
    Edit.Anchors := [akLeft, akTop, akRight];
    Edit.Text := 'TNewEdit';
    Edit.Parent := Form;

    OKButton := TNewButton.Create(Form);
    OKButton.Parent := Form;
    OKButton.Left := Form.ClientWidth - ScaleX(75 + 6 + 75 + 10);
    OKButton.Top := Form.ClientHeight - ScaleY(23 + 10);
    OKButton.Width := ScaleX(75);
    OKButton.Height := ScaleY(23);
    OKButton.Anchors := [akRight, akBottom]
    OKButton.Caption := 'OK';
    OKButton.ModalResult := mrOk;
    OKButton.Default := True;

    CancelButton := TNewButton.Create(Form);
    CancelButton.Parent := Form;
    CancelButton.Left := Form.ClientWidth - ScaleX(75 + 10);
    CancelButton.Top := Form.ClientHeight - ScaleY(23 + 10);
    CancelButton.Width := ScaleX(75);
    CancelButton.Height := ScaleY(23);
    CancelButton.Anchors := [akRight, akBottom]
    CancelButton.Caption := 'Cancel';
    CancelButton.ModalResult := mrCancel;
    CancelButton.Cancel := True;

    Form.ActiveControl := Edit;
    { Keep the form from sizing vertically since we don't have any controls which can size vertically }
    Form.KeepSizeY := True;
    { Center on WizardForm. Without this call it will still automatically center, but on the screen }
    Form.FlipSizeAndCenterIfNeeded(True, WizardForm, False);

    if Form.ShowModal() = mrOk then
      MsgBox('You clicked OK.', mbInformation, MB_OK);
  finally
    Form.Free();
  end;
end;
0 голосов
/ 29 февраля 2020

Вы проверили Установить Designer для Inno Setup?

Это новый инструмент, который поможет вам легко создавать диалоговые страницы Inno Setup без каких-либо сценариев (редактор WYSIWIG с Drag & Drop).

С этим гораздо быстрее создать любую страницу в Inno Setup, чем писать код вручную.

(Я разработчик этого инструмента, и если у вас есть какие-либо проблемы, не стесняйтесь задавать любые вопросы здесь на SO).

...