In the Inno script, I am using the language selection drop down. I am also storing the selected language to a file called "language.properties" using the below code. The installed application uses this "language.properties" file.
procedure CurStepChanged(CurStep: TSetupStep);
var
S: string;
begin
if CurStep = ssPostInstall then
begin
S := Format('language=%s', [ActiveLanguage]);
SaveStringToFile(ExpandConstant('{app}') + '\language.properties', S, False);
end;
end;
Now apart from language selection, I need to add a region selection drop down. The values for the regions is custom, (like America, Europe etc) meaning which there is no need to take from the windows registry.
When the user has selected the region, I need to store that to the same file "language.properties"
I am very new to Inno script. What do you think? How can this be done efficiently?
Edit: Since form the initial comments, it is not possible to customize the "Select Setup Language" dialog, how to add a custom wizard page for region selection?
This is a snippet of my application settings page. I have cut it down:
function AppSettings_CreatePage(PreviousPageId: Integer): Integer;
var
Page: TWizardPage;
iUserValue: Cardinal;
strPath: String;
begin
Page := CreateCustomPage(
PreviousPageId,
ExpandConstant('{cm:ApplicationPreferences}'),
ExpandConstant('{cm:DefaultSettings}')
);
// lblInfo
lblInfo := TLabel.Create(Page);
with lblInfo do
begin
Parent := Page.Surface;
Caption := ExpandConstant('{cm:SpecifyDefaultSettings}');
Left := ScaleX(8);
Top := ScaleY(8);
Width := ScaleX(387);
Height := ScaleY(29);
end;
// lblDatabase
lblDatabase := TLabel.Create(Page);
with lblDatabase do
begin
Parent := Page.Surface;
Caption := ExpandConstant('{cm:DatabaseLanguage}');
Left := ScaleX(8);
Top := ScaleY(112);
Width := ScaleX(385);
Height := ScaleY(13);
end;
// cbDatabase
cbDatabase := TNewComboBox.Create(Page);
with cbDatabase do
begin
Parent := Page.Surface;
Left := ScaleX(8);
Top := ScaleY(128);
Width := ScaleX(177);
Height := ScaleY(21);
Style := csDropDownList;
TabOrder := 3;
// Languages
Items.Add({#LANG_AFK});
Items.Add({#LANG_TWI});
Items.Add({#LANG_DAN});
Items.Add({#LANG_DEU});
Items.Add({#LANG_ENG});
Items.Add({#LANG_ESP});
Items.Add({#LANG_FRA});
Items.Add({#LANG_IND});
Items.Add({#LANG_ITA});
Items.Add({#LANG_SWK});
Items.Add({#LANG_NLD});
Items.Add({#LANG_PLK});
Items.Add({#LANG_PTB});
Items.Add({#LANG_RUS});
Items.Add({#LANG_SQI});
Items.Add({#LANG_FIN});
Items.Add({#LANG_SVE});
Items.Add({#LANG_FPO});
Items.Add({#LANG_TRK});
Items.Add({#LANG_CHS});
Items.Add({#LANG_BGR});
Items.Add({#LANG_ELL});
Items.Add({#LANG_UKR});
Items.Add({#LANG_KHM});
Items.Add({#LANG_ROM});
Items.Add({#LANG_SMO});
Items.Add({#LANG_VIT});
Items.Add({#LANG_ARA});
// Get path where the program was last install
strPath := GetPathInstalled('Public Talks');
if ActiveLanguage = 'English' then ItemIndex := {#MDB_ENG_INDEX};
if ActiveLanguage = 'German' then ItemIndex := {#MDB_DEU_INDEX};
if ActiveLanguage = 'Spanish' then ItemIndex := {#MDB_ESP_INDEX};
if ActiveLanguage = 'Italian' then ItemIndex := {#MDB_ITA_INDEX};
if ActiveLanguage = 'Dutch' then ItemIndex := {#MDB_NLD_INDEX};
if ActiveLanguage = 'Turkish' then ItemIndex := {#MDB_TRK_INDEX};
if ActiveLanguage = 'Portuguese' then ItemIndex := {#MDB_PTB_INDEX};
if ActiveLanguage = 'Swedish' then ItemIndex := {#MDB_SVE_INDEX};
if ActiveLanguage = 'Danish' then ItemIndex := {#MDB_DAN_INDEX};
if ActiveLanguage = 'Russian' then ItemIndex := {#MDB_RUS_INDEX};
if ActiveLanguage = 'Finnish' then ItemIndex := {#MDB_FIN_INDEX};
if ActiveLanguage = 'Albanian' then ItemIndex := {#MDB_SQI_INDEX};
if ActiveLanguage = 'French' then ItemIndex := {#MDB_FRA_INDEX};
if ActiveLanguage = 'Greek' then ItemIndex := {#MDB_ELL_INDEX};
if ActiveLanguage = 'Romanian' then ItemIndex := {#MDB_ROM_INDEX};
end;
Result := Page.ID;
end;
That shows you how to show a drop list and select an entry.
I should point out that this is also referred to in the Help File supplied with Inno Setup that is also available online. See TNewComboBox topic. I admit it is rather sparse!
Related
I have two #Martin Prikryl codes that I can't get them to work together.
Larger "Select Components" page in Inno Setup
Long descriptions on Inno Setup components
I followed all the instructions Martin said about the #TLama code, but the codes didn't work together.
Component captions do not appear when I activate the code to change the page height.
I would like a way to merge them and make them work together.
I solved the problem by adding the page's custom height value to the CompLabel.Top of the component captions code.
I also had to change the procedure to CurPageChanged and created an <event( ' ' )> to merge the two codes and created a directive #define CustomPageHeight "ScaleY(200)" to define the custom height of the page.
// Set page height here
#define CustomPageHeight "ScaleY(200)"
[Code]
// Final part of code for component captions
Var StopCall: Boolean;
<event('CurPageChanged')> // Added event here
Procedure CurPageChanged1(CurPageID: Integer);
Begin
If StopCall = false Then
Begin
If CurPageID = wpWelcome Then
Begin
SetTimer(0, 0, 50, CreateCallback(#HoverTimerProc));
CompLabel := TLabel.Create(WizardForm);
CompLabel.Parent := WizardForm.SelectComponentsPage;
CompLabel.Left := WizardForm.ComponentsList.Left;
CompLabel.Width := WizardForm.ComponentsList.Width;
CompLabel.Height := ScaleY(37); // Added here
CompLabel.Top := WizardForm.ComponentsList.Top + WizardForm.ComponentsList.Height + {#CustomPageHeight} - CompLabel.Height;
CompLabel.AutoSize := False;
CompLabel.WordWrap := True;
WizardForm.ComponentsList.Height := WizardForm.ComponentsList.Height - CompLabel.Height - ScaleY(2);
StopCall := true;
End;
End;
End;
// Code for custom height page
var
CompPageModified: Boolean;
<event('CurPageChanged')> // Added event here
procedure CurPageChanged2(CurPageID: Integer);
begin
if CurpageID = wpSelectComponents then
begin // Changed here
WizardForm.Height := WizardForm.Height + {#CustomPageHeight};
CompPageModified := True;
end
else
if CompPageModified then
begin // Changed here
WizardForm.Height := WizardForm.Height - {#CustomPageHeight};
CompPageModified := False;
end;
end;
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;
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;
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
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.