Inno Setup Update custom TSetupForm caption with nested TNewNotebook page change - inno-setup

I want to use custom uninstall wizard pages as in my Inno Setup script shown in question Custom Uninstall page (not MsgBox).
The problem I have is that the Caption of the TSetupForm does not update, when a page changes.
I tried using the following code.
[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;
Please help me to find why Caption of the TSetupForm (Here it is declared as Form) never updates.
Thanks in advance.

Of course, it doesn't. You have to update the form caption as the page changes.
A good place for this is the end of the UpdateButtonsState function:
procedure UpdateButtonsState(Form: TSetupForm);
{ ... }
begin
{ ... }
if Notebook.ActivePage <> nil then
Form.Caption := 'CAPTION - ' + IntToStr(Notebook.ActivePage.PageIndex + 1);
end;

Related

Inno Setup - Create custom message box (yes / no)

How to create custom message box similar to this code: Inno Setup - Hide X button (close) at message box (for a message box with one button) but with two buttons, yes/no, with the possibility of different actions for each election.
Just add the second TButton:
function MyYesNoMessageBox: Integer;
var
Form: TSetupForm;
YesButton, NoButton: TNewButton;
MesssageLabel: TLabel;
begin
Form := CreateCustomForm;
Form.BorderStyle := bsDialog;
Form.Position := poOwnerFormCenter;
Form.ClientWidth := ScaleX(400);
Form.ClientHeight := ScaleY(130);
Form.Caption := 'Caption';
MesssageLabel := TLabel.Create(Form);
MesssageLabel.Parent := Form;
MesssageLabel.Left := ScaleX(16);
MesssageLabel.Top := ScaleX(16);
MesssageLabel.Width := Form.ClientWidth - 2*ScaleX(16);
MesssageLabel.Height := ScaleY(32);
MesssageLabel.AutoSize := False;
MesssageLabel.WordWrap := True;
MesssageLabel.Caption := 'Lorem ipsum dolor sit amet, ...';
YesButton := TNewButton.Create(Form);
YesButton.Parent := Form;
YesButton.Width := ScaleX(80);
YesButton.Height := ScaleY(24);
YesButton.Left := Form.ClientWidth - 2 * (YesButton.Width + ScaleX(8));
YesButton.Top := Form.ClientHeight - YesButton.Height - ScaleY(8);
YesButton.Caption := '&Yes';
YesButton.ModalResult := mrYes;
NoButton := TNewButton.Create(Form);
NoButton.Parent := Form;
NoButton.Width := YesButton.Width;
NoButton.Height := YesButton.Height;
NoButton.Left := YesButton.Left + YesButton.Width + ScaleX(8);
NoButton.Top := YesButton.Top;
NoButton.Caption := '&No';
NoButton.ModalResult := mrNo;
Result := Form.ShowModal;
end;
And test return code of Form.ShowModal (or check Form.ModalResult):
if MyYesNoMessageBox = mrYes then
begin
MsgBox('Yes selected', mbInformation, MB_OK);
end
else
begin
MsgBox('No selected', mbInformation, MB_OK);
end;

How to copy strings from StringList to multiple Memos

i have a text file and 10 StringLists, i want to open the txt files in the 10 StringLists, for example the text file has 1000 line, i want the first 100 line in StringList1 and the second 100 in StringLists2 and so on, my idea is to get text file lines count and divide it by 10 then copy each 100 in the 10 StringLists
var
i, x :integer;
U : TStrings;
DatFile ,ExePath:string;
begin
U := TStringList.Create;
ExePath := ExtractFilePath(Application.ExeName);
DatFile := ExePath + 'Test.txt';
U.LoadFromFile(DatFile);
x := U.Count Div 10;
Edit1.Text := IntToStr(x);
/// Stoped here
end;
how to continue this?
You can use an array to hold the Memo pointers, and then loop through the lines of the file, calculating which array index to add each line to, eg:
var
i, LinesPerMemo, LinesAdded: integer;
U : TStrings;
DatFile: string;
Memos: array[0..9] of TMemo;
CurMemo: TMemo;
begin
Memos[0] := Memo1;
Memos[1] := Memo2;
Memos[2] := Memo3;
Memos[3] := Memo4;
Memos[4] := Memo5;
Memos[5] := Memo6;
Memos[6] := Memo7;
Memos[7] := Memo8;
Memos[8] := Memo9;
Memos[9] := Memo10;
DatFile := ExtractFilePath(Application.ExeName) + 'Test.txt';
U := TStringList.Create;
try
U.LoadFromFile(DatFile);
LinesPerMemo := U.Count div 10;
if (U.Count mod 10) <> 0 then
Inc(LinesPerMemo);
Edit1.Text := IntToStr(LinesPerMemo);
J := 0;
CurMemo := Memos[J];
try
LinesAdded := 0;
for I := 0 to U.Count-1 do
begin
CurMemo.Lines.Add(U[I]);
Inc(LinesAdded);
if (LinesAdded = LinesPerMemo) and (J < 9) then
begin
CurMemo.Lines.EndUpdate;
Inc(J);
CurMemo := Memos[J];
CurMemo.Lines.BeginUpdate;
LinesAdded := 0;
end;
finally
CurMemo.Lines.EndUpdate;
end;
end;
finally
U.Free;
end;
end;
Alternatively, use a temp TStringList to collect the lines for each Memo:
var
i, LinesPerMemo: integer;
U, Lines : TStrings;
DatFile: string;
Memos: array[0..9] of TMemo;
begin
Memos[0] := Memo1;
Memos[1] := Memo2;
Memos[2] := Memo3;
Memos[3] := Memo4;
Memos[4] := Memo5;
Memos[5] := Memo6;
Memos[6] := Memo7;
Memos[7] := Memo8;
Memos[8] := Memo9;
Memos[9] := Memo10;
DatFile := ExtractFilePath(Application.ExeName) + 'Test.txt';
U := TStringList.Create;
try
U.LoadFromFile(DatFile);
LinesPerMemo := U.Count div 10;
if (U.Count mod 10) <> 0 then
Inc(LinesPerMemo);
Edit1.Text := IntToStr(LinesPerMemo);
Lines := TStringList.Create;
try
J := 0;
for I := 0 to U.Count-1 do
begin
Lines.Add(U[I]);
if (Lines.Count = LinesPerMemo) and (J < 9) then
begin
Memos[J].Lines.Assign(Lines);
Inc(J);
Lines.Clear;
end;
end;
Memos[J].Lines.Assign(Lines);
finally
Lines.Free;
end;
finally
U.Free;
end;
end;
To speed up, you can use Texfile and Tstringstream with creating Tmemo if needed.
type
TForm1 = class(TForm)
Button1: TButton;
ScrollBox1: TScrollBox;
procedure Button1Click(Sender: TObject);
private
{ Déclarations privées }
function getNewMemo(const aStream : Tstream) : TMemo;
public
{ Déclarations publiques }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
const nblines : Integer = 100;
var F : TextFile;
sLine, sfile : string;
cpt : Integer;
Memo : TMemo;
tmp : TStringStream;
begin
sfile := 'C:\TEMP\Test.txt';
tmp := TStringStream.Create;
AssignFile(F, sFile);
Reset(F);
try
LockWindowUpdate(ScrollBox1.Handle);
cpt := 0;
while not Eof(F) do begin
Readln(F, sLine);
Inc(cpt);
tmp.WriteString(sLine + #13);
if (cpt mod nbLines = 0) then begin
Memo := getNewMemo(tmp);
tmp.Clear;
end;
end;
if tmp.Size > 0 then begin
Memo := getNewMemo(tmp);
tmp.Clear;
end;
finally
CloseFile(F);
tmp.Free;
LockWindowUpdate(0);
end;
end;
function TForm1.getNewMemo(const aStream : Tstream): TMemo;
begin
Result := TMemo.Create(ScrollBox1);
Result.Parent := ScrollBox1;
Result.Top := High(integer);
Result.Align := alTop;
Result.Height := 150;
Result.ScrollBars := ssBoth;
if aStream <> nil then begin
aStream.Seek(0, soFromBeginning);
Result.Lines.LoadFromStream(aStream);
end;
end;
end.

INNO setup: how to adjust the components inner window

I'm trying to create a custom component window. So far i have found some code here on stackoverflow that lets me set the outerwindow height of the components window. The problem i have is that the actual component selection box doesnt grow with it, like i have a big window but still a small component selection box.
Picture of my problem:
Hope someone can help me with this.
The code i have is this
var
DefaultTop,
DefaultLeft,
DefaultHeight,
DefaultBackTop,
DefaultNextTop,
DefaultCancelTop,
DefaultBevelTop,
DefaultOuterHeight: Integer;
const
LicenseHeight = 600;
LicenseWidth = 600;
procedure InitializeWizard();
begin
DefaultTop := WizardForm.Top;
DefaultLeft := WizardForm.Left;
DefaultHeight := WizardForm.Height;
DefaultBackTop := WizardForm.BackButton.Top;
DefaultNextTop := WizardForm.NextButton.Top;
DefaultCancelTop := WizardForm.CancelButton.Top;
DefaultBevelTop := WizardForm.Bevel.Top;
end;
procedure CurPageChanged(CurPageID: Integer);
begin
if CurPageID = wpSelectComponents then
begin
WizardForm.Top := DefaultTop - (LicenseHeight - DefaultHeight) div 2;
WizardForm.Height := LicenseHeight;
WizardForm.Width := LicenceWidth;
WizardForm.OuterNotebook.Height := WizardForm.OuterNotebook.Height + (LicenseHeight - DefaultHeight);
WizardForm.CancelButton.Top := DefaultCancelTop + (LicenseHeight - DefaultHeight);
WizardForm.NextButton.Top := DefaultNextTop + (LicenseHeight - DefaultHeight);
WizardForm.BackButton.Top := DefaultBackTop + (LicenseHeight - DefaultHeight);
WizardForm.Bevel.Top := DefaultBevelTop + (LicenseHeight - DefaultHeight);
end
else
begin
WizardForm.Top := DefaultTop;
WizardForm.Left := DefaultLeft;
WizardForm.Height := DefaultHeight;
WizardForm.OuterNotebook.Height := DefaultOuterHeight;
WizardForm.CancelButton.Top := DefaultCancelTop;
WizardForm.NextButton.Top := DefaultNextTop;
WizardForm.BackButton.Top := DefaultBackTop;
WizardForm.Bevel.Top := DefaultBevelTop;
end;
end;

How to put different color for the text in a TNewStaticText in inno setup

I have a variable of TNewStaticText datatype and i want to set different colors for the text, For example
if the the variable contains text like "Have a nice day"
"Have" should be displayed in red color
"a nice" should be displayed in blue color
"day" should be displayed in black color
Font color you can change with the Font.Color property, but it's for the whole control's text. For your aim you need to create three controls. Here is an example:
[Setup]
AppName=My Program
AppVersion=1.5
DefaultDirName={pf}\My Program
[Code]
procedure InitializeWizard;
var
TopPos: Integer;
LeftPos: Integer;
StaticText: TNewStaticText;
begin
TopPos := WizardForm.NextButton.Top;
LeftPos := 8;
StaticText := TNewStaticText.Create(WizardForm);
StaticText.Parent := WizardForm;
StaticText.Left := LeftPos;
StaticText.Top := TopPos;
StaticText.Font.Color := clRed;
StaticText.Caption := 'Have ';
LeftPos := StaticText.Left + StaticText.Width;
StaticText := TNewStaticText.Create(WizardForm);
StaticText.Parent := WizardForm;
StaticText.Left := LeftPos;
StaticText.Top := TopPos;
StaticText.Font.Color := clBlue;
StaticText.Caption := 'a nice ';
LeftPos := StaticText.Left + StaticText.Width;
StaticText := TNewStaticText.Create(WizardForm);
StaticText.Parent := WizardForm;
StaticText.Left := LeftPos;
StaticText.Top := TopPos;
StaticText.Font.Color := clBlack;
StaticText.Caption := 'day!';
end;
Or, to make your code more flexible, you can wrap this process to a function like follows:
[Setup]
AppName=My Program
AppVersion=1.5
DefaultDirName={pf}\My Program
[Code]
type
TColorArray = array of TColor;
procedure CreateColoredText(const ATexts: TArrayOfString; const AColors: TColorArray;
AParent: TWinControl; ALeft, ATop: Integer);
var
I: Integer;
LeftPos: Integer;
begin
if GetArrayLength(ATexts) <> GetArrayLength(AColors) then
RaiseException('Inconsistent array parameters.');
LeftPos := ALeft;
for I := 0 to GetArrayLength(ATexts) - 1 do
begin
with TNewStaticText.Create(AParent) do
begin
Parent := AParent;
Left := LeftPos;
Top := ATop;
Font.Color := AColors[I];
Caption := ATexts[I];
LeftPos := Left + Width;
end;
end;
end;
procedure InitializeWizard;
begin
CreateColoredText(['Have ', 'a nice ', 'day!'], [clRed, clBlue, clBlack],
WizardForm, 8, WizardForm.NextButton.Top);
end;
You might want to try something like this:
procedure FormButtonOnClick(Sender: TObject);
var
Form: TSetupForm;
OKButton, CancelButton: TNewButton;
begin
Form := CreateCustomForm();
try
Form.ClientWidth := ScaleX(256);
Form.ClientHeight := ScaleY(256);
Form.Caption := 'TSetupForm';
Form.CenterInsideControl(WizardForm, False);
OKButton := TNewButton.Create(Form);
OKButton.Parent := Form;
OKButton.Width := ScaleX(75);
OKButton.Height := ScaleY(23);
OKButton.Left := Form.ClientWidth - ScaleX(75 + 6 + 75 + 10);
OKButton.Top := Form.ClientHeight - ScaleY(23 + 10);
OKButton.Caption := 'OK';
OKButton.ModalResult := mrOk;
CancelButton := TNewButton.Create(Form);
CancelButton.Parent := Form;
CancelButton.Width := ScaleX(75);
CancelButton.Height := ScaleY(23);
CancelButton.Left := Form.ClientWidth - ScaleX(75 + 10);
CancelButton.Top := Form.ClientHeight - ScaleY(23 + 10);
CancelButton.Caption := 'Cancel';
CancelButton.ModalResult := mrCancel;
CancelButton.Cancel := True;
Form.ActiveControl := OKButton;
if Form.ShowModal() = mrOk then
MsgBox('You clicked OK.', mbInformation, MB_OK);
finally
Form.Free();
end;
end;
This example is copied from .htm">http://read.pudn.com/downloads115/sourcecode/windows/system/488914/Examples/CodeClasses.iss_.htm

Inno setup WordWrap and Autosize

I'm creating a setup using Inno Setup, and I changed license page to not show license, but to link to it instead. I also added a StaticText to show some text, and the problem is that when I add too much text, I need WordWrap := true, and AutoSize := false, and this makes StaticText width in Setup created really small. Why it is sized if AutoSize = false? What to do to prevent it from minimizing when WordWrap = true. Change parent?
procedure InitializeWizard;
var
FormButton: TNewButton;
Page: TWizardPage;
ComboBox: TNewComboBox;
begin
WizardForm.LicenseAcceptedRadio.Hide;
WizardForm.LicenseNotAcceptedRadio.Hide;
LicenseContextText := TNewStaticText.Create(WizardForm.InnerPage);
with LicenseContextText do
begin
Parent := WizardForm.InnerPage;
//TODO: check if we need
Left := ScaleX(250);
Top := ScaleY(50);
Height := ScaleY(100);
Width := ScaleX(1000); //200;
//Color := clBlack;
Font.Color := clGray;
//WordWrap := true;
//AutoSize := false;
Caption := 'Some content text, Some content text, Some content text';//
Visible := false;
end;
LicenseLinkLabel := TNewStaticText.Create(WizardForm.InnerPage);
with LicenseLinkLabel do
begin
Parent := WizardForm.InnerPage;
//TODO: check if we need
Left := 340;
Top := 240;
Height := 100;
Cursor := crHand;
Font.Color := clBlue;
Font.Style := [fsUnderline];
Caption := 'the License Agreement';
OnClick := #LicenseLinkLabelClick;
Visible := false;
end;
LicenseLinkURL := TNewCheckBox.Create(WizardForm.InnerPage);
with LicenseLinkURL do
begin
Parent := WizardForm.InnerPage;
Left := 277;
Top := 238;
Width := 60;
Caption := ' I accept';
OnClick := #OnLicenseCheckBoxClick;
Visible := false;
end;
end;
procedure CurPageChanged(CurPageID: Integer);
begin
if (CurPageID = wpLicense) then
begin
WizardForm.Bevel1.Visible := false;
WizardForm.MainPanel.Visible := false;
WizardForm.InnerNotebook.Visible := false;
LicenseLinkLabel.Visible := true;
LicenseLinkURL.Visible := true;
LicenseContextText.Visible := true;
Set the AutoSize and WordWrap properties before you set the Width and Height properties.
This is unrelated, but also rather than hard-coding specific values for the sizes you might want to consider using sizes relative to existing elements in the WizardForm, to eg. have it automatically fit to the width of the page area within the form.

Resources