Inno安装程序更新嵌套TNewNotebook页面更改的自定义TSetupForm标题

问题描述:

我想使用自定义卸载向导页面,如问题Custom Uninstall page (not MsgBox)中所示的我的Inno安装脚本中。Inno安装程序更新嵌套TNewNotebook页面更改的自定义TSetupForm标题

我遇到的问题是当页面更改时TSetupFormCaption不会更新。

我试着用下面的代码。

[Code] 

const 
    ControlGap = 5; 

procedure UpdateButtonsState(Form: TSetupForm); 
var 
    Notebook: TNewNotebook; 
    BtnBack, BtnNext: TButton; 
begin 
    Notebook := TNewNotebook(Form.FindComponent('Notebook')); 
    BtnBack := TButton(Form.FindComponent('BtnBack')); 
    BtnNext := TButton(Form.FindComponent('BtnNext')); 

    BtnBack.Enabled := (Notebook.ActivePage <> Notebook.Pages[0]); 
    if Notebook.ActivePage <> Notebook.Pages[Notebook.PageCount - 1] then 
    begin 
    BtnNext.Caption := SetupMessage(msgButtonNext) 
    BtnNext.ModalResult := mrNone; 
    end 
    else 
    begin 
    BtnNext.Caption := SetupMessage(msgButtonFinish); 
    BtnNext.ModalResult := mrYes; 
    end; 
end; 

procedure BtnPageChangeClick(Sender: TObject); 
var 
    NextPage: TNewNotebookPage; 
    Notebook: TNewNotebook; 
    Form: TWinControl; 
    Button, BtnBack, BtnNext: TButton; 
begin 
    Button := TButton(Sender); 
    Form := Button; 
    while not (Form is TSetupForm) do 
    Form := Form.Parent; 
    Notebook := TNewNotebook(Form.FindComponent('Notebook')); 
    BtnBack := TButton(Form.FindComponent('BtnBack')); 
    BtnNext := TButton(Form.FindComponent('BtnNext')); 

    if (Button = BtnBack) and (Notebook.ActivePage = Notebook.Pages[0]) then 
    NextPage := nil 
    else 
    if (Button = BtnNext) and (Notebook.ActivePage = Notebook.Pages[Notebook.PageCount - 1]) then 
    NextPage := nil 
    else 
    NextPage := Notebook.FindNextPage(Notebook.ActivePage, Button = BtnNext); 
    Notebook.ActivePage := NextPage; 

    UpdateButtonsState(TSetupForm(Form)); 
end; 

function AddPage(NotebookForm: TSetupForm): TNewNotebookPage; 
var 
    Notebook: TNewNotebook; 
begin 
    Notebook := TNewNotebook(NotebookForm.FindComponent('Notebook')); 
    Result := TNewNotebookPage.Create(Notebook); 
    Result.Notebook:=Notebook; 
    Result.Parent:=Notebook; 
    Result.Align := alClient; 
    if Notebook.ActivePage = nil then 
    Notebook.ActivePage := Result; 
    UpdateButtonsState(NotebookForm); 
end; 

function CreateNotebookForm: TSetupForm; 
var 
    Notebook: TNewNotebook; 
    NotebookPage: TNewNotebookPage; 
    Pan: TPanel; 
    TmpLabel: TLabel; 
    MaxWidth, i: Integer; 
    BtnBack, BtnNext, BtnCancel: TButton; 
    BtnLabelMsgIDs: Array Of TSetupMessageID; 
begin 
    Result := CreateCustomForm; 
    Result.SetBounds(0, 0, UninstallProgressForm.Width, UninstallProgressForm.Height); 
    Result.Position := poOwnerFormCenter; 

    Notebook := TNewNotebook.Create(Result); 
    Notebook.Parent := Result; 
    Notebook.Name := 'Notebook'; 
    Notebook.Align := alClient; 

    Pan := TPanel.Create(Result); 
    Pan.Parent := Notebook; 
    Pan.Caption := ''; 
    Pan.Align := alBottom; 

    BtnNext := TNewButton.Create(Result); 
    with BtnNext do 
    begin 
    Parent := Pan; 
    Name := 'BtnNext'; 
    Caption := SetupMessage(msgButtonNext); 
    OnClick := @BtnPageChangeClick; 
    ParentFont := True; 
    end; 

    BtnBack := TNewButton.Create(Result); 
    with BtnBack do 
    begin 
    Parent := Pan; 
    Caption := SetupMessage(msgButtonBack); 
    Name := 'BtnBack'; 
    OnClick := @BtnPageChangeClick; 
    ParentFont := True; 
    end; 

    BtnCancel := TNewButton.Create(Result); 
    with BtnCancel do 
    begin 
    Parent := Pan; 
    Name := 'BtnCancel'; 
    Caption := SetupMessage(msgButtonCancel); 
    ModalResult := mrCancel; 
    Cancel := True; 
    ParentFont := True; 
    end; 

    TmpLabel := TLabel.Create(Result); 
    with TmpLabel do 
    begin 
    Left := 0; 
    Top := 0; 
    Parent := Pan; 
    ParentFont := True; 
    Visible := False; 
    WordWrap := False; 
    Autosize := True; 
    end; 

    SetArrayLength(BtnLabelMsgIDs, 4); 
    BtnLabelMsgIDs[0] := msgButtonBack; 
    BtnLabelMsgIDs[1] := msgButtonNext; 
    BtnLabelMsgIDs[2] := msgButtonCancel; 
    BtnLabelMsgIDs[3] := msgButtonFinish; 
    MaxWidth := 0; 
    for i := Low(BtnLabelMsgIDs) to High(BtnLabelMsgIDs) do 
    begin 
    TmpLabel.Caption := SetupMessage(BtnLabelMsgIDs[i]) + 'WWW'; 
    if MaxWidth < TmpLabel.Width then 
     MaxWidth := TmpLabel.Width; 
    end; 

    TmpLabel.Caption := 'Yy'; 

    with BtnBack do 
    begin 
    Width := MaxWidth; 
    Height := TmpLabel.Height*2; 
    Left := Parent.ClientWidth - 3*(MaxWidth + ScaleX(ControlGap)); 
    Top := (Parent.ClientHeight - Height) div 2; 
    end; 
    with BtnNext do 
    begin 
    Width := MaxWidth; 
    Height := TmpLabel.Height*2; 
    Left := Parent.ClientWidth - 2*(MaxWidth + ScaleX(ControlGap)); 
    Top := (Parent.ClientHeight - Height) div 2; 
    end; 
    with BtnCancel do 
    begin 
    Width := MaxWidth; 
    Height := TmpLabel.Height*2; 
    Left := Parent.ClientWidth - 1*(MaxWidth + ScaleX(ControlGap)); 
    Top := (Parent.ClientHeight - Height) div 2; 
    end; 
end; 

procedure InitializeUninstallProgressForm; 
var 
    Form: TSetupForm; 
    i: Integer; 
    NotebookPage: TNewNotebookPage; 
    ModResult: Integer; 
begin 
    Form := CreateNotebookForm; 
    for i := 1 to 4 do 
    begin 
    NotebookPage := AddPage(Form); 
    with NotebookPage do 
    begin 
     Color := clWindow; 
     with TLabel.Create(Form) do 
     begin 
     Parent := NotebookPage; 
     SetBounds(0, 0, 50, 30); 
     Autosize := true; 
     Font.Size := 14; 
     Caption := 'Label ' + IntToStr(i); 
     end; 
     Form.Caption := 'CAPTION - ' + IntToStr(i); 
     {<<<NEVER UPDATES AND KEEPS SHOWING "CAPTION - 4">>>>} 
    end; 
    end; 

    ModResult := Form.ShowModal; 
    if ModResult = mrYes then 
    MsgBox('Continuing uninstall', mbInformation, MB_OK) 
    else 
    begin 
    MsgBox('Cancelled', mbInformation, MB_OK); 
    Abort; 
    end; 
end; 

请帮我找,为什么TSetupFormCaption(这被声明为Form)从来没有更新。

在此先感谢。

当然,它没有。您必须在页面更改时更新表格标题。

这样做的一个很好的地方是UpdateButtonsState函数的末尾:

procedure UpdateButtonsState(Form: TSetupForm); 
{ ... } 
begin 
    { ... } 
    if Notebook.ActivePage <> nil then 
    Form.Caption := 'CAPTION - ' + IntToStr(Notebook.ActivePage.PageIndex + 1); 
end; 
+0

它的工作......谢谢!现在我明白了......当我在模态窗体中单击“完成”时,即使在添加了行if'(Form nil)和(Notebook nil)后,我总是收到错误“Could not call proc”然后'在你的建议行之前.......为什么这样? – Blueeyes789

+0

查看我更新的答案。 –

+0

谢谢你的回答! – Blueeyes789