2016-12-06 7 views
0

質問Custom Uninstall page (not MsgBox)に示されているInno Setupスクリプトのように、カスタムアンインストールウィザードページを使用します。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として宣言されている)を更新したことがない理由を見つけるために私を助けてください。

ありがとうございます。

答えて

1

もちろん、そうではありません。ページの変更に応じて、フォームキャプションを更新する必要があります。

このために良い場所がUpdateButtonsState関数の最後である:

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

それは働いていた......ありがとう! (Form <> nil)と(Notebook <> nil)という行を追加した後でも、Modal Formで "Finish"をクリックするとエラーが "Could not call proc"あなたの提案ラインの前に 'それはなぜですか?これはなぜですか? – Blueeyes789

+0

私の更新答えを見てください。 –

+0

ありがとうございました! – Blueeyes789

関連する問題