Inno Setup Place controls on wpPreparing Page - inno-setup

I am trying to place a label on the wpPreparing page to indicate uninstallation of an existing version, prior to running the new installation. Here is my code:
function PrepareToInstall(var NeedsRestart: Boolean): String;
var
UninstallingLabel: TNewStaticText;
intResultCode: Integer;
begin
with UninstallingLabel do
begin
Caption := 'Uninstalling existing version...';
Left := WizardForm.StatusLabel.Left;
Top := WizardForm.StatusLabel.Top;
Parent := wpPreparing.Surface;
end;
if strExistingInstallPath <> '' then
begin
Exec(GetUninstallString, '/verysilent /suppressmsgboxes', '', SW_HIDE,
ewWaitUntilTerminated, intResultCode);
end;
end;
The trouble is it does not seem to like Parent := wpPreparing.Surface and compiling fails with a
Semicolon (;) expected
error. This syntax works when adding a label to a custom created page. Why does this fail when trying to add it to wpPreparing?

The wpPreparing is not an object, it's just a numerical constant.
The WizardForm.PreparingPage holds a reference to the "Preparing to Install" page. Note that it is of type TNewNotebookPage already, not TWizardPage. So you use it directly as a parent.
Also note that the StatusLabel is on the "Installing" page. You probably want to relate your new label to the PreparingLabel instead.
And you have to create the UninstallingLabel.
UninstallingLabel := TNewStaticText.Create(WizardForm);
with UninstallingLabel do
begin
Caption := 'Uninstalling existing version...';
Left := WizardForm.PreparingLabel.Left;
Top := WizardForm.PreparingLabel.Top;
Parent := WizardForm.PreparingPage;
end;
Though do you really want to shadow the PreparingLabel (as you use its coordinates).
What about reusing it instead?
WizardForm.PreparingLabel.Caption := 'Uninstalling existing version...';

I've replayed your code. It works if you use just WizardForm as the parent. But it's in the top left corner of the form...
wpPreparing is the name of a constant that holds the ID of the correspnding page.
And you have to create an instance of UninstallingLabel

Related

Remove image from the last Finished page of Inno Setup

How to customize last page (wpFinished) to only have a message, but keep the bottom buttons, like this:
I don't want the image on the left that is there by default.
I was trying to create new page, but don't know how to hide the default finished page or add bottom buttons (Back, Finished, Cancel) on new page.
Hide the WizardBitmapImage2 control and extend remaining controls accordingly.
Something like this:
[Code]
procedure ExtendFinishedPageControl(Control: TControl);
begin
Control.Left := Control.Left - WizardForm.WizardBitmapImage2.Width;
Control.Width := Control.Width + WizardForm.WizardBitmapImage2.Width;
end;
procedure InitializeWizard();
begin
WizardForm.WizardBitmapImage2.Visible := False;
ExtendFinishedPageControl(WizardForm.RunList);
ExtendFinishedPageControl(WizardForm.NoRadio);
ExtendFinishedPageControl(WizardForm.YesRadio);
ExtendFinishedPageControl(WizardForm.FinishedLabel);
ExtendFinishedPageControl(WizardForm.FinishedHeadingLabel);
end;

On Delphi how to I reference objects that have been created using just one variable?

I was creating a Form with some buttons in runtime in my application and I realized something that's bothering me a lot and I couldn't figure for myself or anywhere in the internet.
Look at the following code.
procedure TfrmTest.CreateFourButtons(Sender: TObject);
var
i: Integer; B: TButton;
begin
for i := 1 to 4 do
begin
B := TButton.Create(frmTest);
B.Parent := frmTest;
B.SetBounds(250,(70+(30*i)),75,25);
B.Caption := 'Button' + IntToStr(i);
B.Visible := True;
end;
end;
So I just created four buttons at runtime on a form in specific locations. So far so good right?
But now let's imagine that I want to change the Caption property of the first button to "HotPotato"? How do I reference the first button now since I used just one variable to create those buttons? I've been told to store those objects in an array of TButtons or better yet in an TObjectList and these are all fine solutions to this problem. But then one question came to my mind!
Where are those buttons located in the memory? Are the any ways for me to reference them without using arrays or object lists?
The normal way to keep track of multiple similar object is to use an array.
procedure TfrmTest.CreateFourButtons(Sender: TObject);
var
i: Integer;
B: TArray<TButton>; //or array of TButton for older versions
begin
SetLength(B, 4);
for i := 0 to 3 do begin
B[i] := TButton.Create(frmTest);
B[i].Parent := frmTest;
B[i].SetBounds(250,(70+(30*i)),75,25);
B[i].Caption := 'Button' + IntToStr(i);
B[i].Visible := True;
end;
B[0].Caption:= 'HotPotato';
end;
When placing buttons on a form this is not strictly needed, the form already uses a list to keep track of child controls placed on it, but you'll need some way to tell the different buttons apart.
You can use the tag property for this:
for i := 1 to 4 do begin
B := TButton.Create(frmTest);
B.Parent := frmTest;
B.Tag:= i;
...
end;
//This will get inefficient if there are many controls on a form.
for var C in frmTest.Controls do begin //10.3 syntax.
if (C is TButton) and (C.tag = 1) then C.Caption:= 'HotPotato'
end;
The button is an object and it is thus located on the heap. If you lose its reference you will never find it again. However if it is placed on a parent control, then that parent will keep track of it and you can always get it using FindChildControl or the Controls list of the form.
FindChildControl does a search by name. This requires you to set the name of the control, or it will not work.
var B:= frmTest.FindChildControl('Button1');
Note: FindChildControl only locates immediate children of the control. It can't find a control that is a child of one of the control's children.
This locating children can get complicated if the button is located in a subpanel. Better to use the array or a list to keep track of a range of buttons.

Drawing and image on a button in a cell in a TStringGrid

I have a TStringGrid in Lazarus, running on Linux. I have a column which has editor type cbsButton. I want the button to display a certain image, instead of an ellipsis. I have the following code, which causes an error:
procedure TForm1.streams_gridDrawCell(Sender: TObject; aCol, aRow: Integer; aRect: TRect; aState: TGridDrawState);
var
aCanvas: TCanvas;
aGrid: TStringGrid;
Editor: TWinControl;
image: TImage;
begin
if (aCol <> 1) or (aRow = 0) then begin
Exit;
end;
aGrid := (Sender as TStringGrid);
aCanvas := image.Canvas;
aCanvas.FillRect(aRect);
imagelist1.Draw(aCanvas, aRect.Left+2, aRect.Top+2, 8);
Editor := (aGrid.EditorByStyle(cbsButton) as TButtonCellEditor);
Editor.Brush.Style := TBrushStyle.bsImage;
(Editor.Brush.Image as TImage) := image; // causes the error below
end;
The error is:
mainform.pas(156,23) Error: Class or Object types "TFPCustomImage" and
"TImage" are not related
At this point, I'm sure I'm going about this in entirely the wrong way. Could someone please put me back on the right path?
I doubt that the OnDrawCell event is the correct place to modify a cell editor because probably the correct cell editor does not exist at this moment when the cell is painted.
The correct event to define the cell editor is the OnSelectEditor event of the grid. Please read the wiki (http://wiki.lazarus.freepascal.org/Grids_Reference_Page).
The cbsButton editor which you use inherits from TButton. A TButton does not have a Glyph property - you cannot assign a bitmap to the button. But can you write your own cell editor easily, just follow the standard example in examples/gridexamples/gridcelleditor:
Add a TBitBtn to the form. Delete its Caption, add the requested image to the Glyph property. Set the Visible property to false.
In the OnClick event of this button write how you want to edit the cell. Access the cell specified by the properties Col and Row of the grid. As an example, I assume here that you just want to open an InputBox:
procedure TForm1.BitBtn1Click(Sender: TObject);
begin
StringGrid1.Cells[StringGrid1.Col, StringGrid1.Row] :=
InputBox('Input some text', 'Text:', '');
end;
Now write an event handler for the OnSelectEditor event of the grid. It must assign the BitBtn to the Editor parameter of the event and make sure that the button is at the correct position within the selected cell - that's all!
procedure TForm1.StringGrid1SelectEditor(Sender: TObject; aCol, aRow: Integer;
var Editor: TWinControl);
var
R: TRect;
begin
if (aCol=2) and (aRow > 0) then begin
R := StringGrid1.CellRect(aCol, ARow);
R.Left := R.Right - (R.Bottom - R.Top);
BitBtn1.BoundsRect := R;
Editor := BitBtn1;
end;
end;
Editor.Brush.Image is a property of type TFPCustomImage. This is a TPersistent descendant. And TImage is a descendant of TCustomImage and thus TGraphicControl and TControl. So these are entirely different classes that are not compatible.
So you are not expected to cast (Editor.Brush.Image as TImage) and assign any TImage instance to it.

Change WizardSmallImageFile programmatically - Inno Setup

Is it possible to change the top image on a wizard form depending on the wizard form. I can change the left side image but would like to change the top (small image).
procedure CurPageChanged(CurPageID: Integer);
begin
if CurPageID = 4 then
filename:= 'babylontoolbar.bmp'
else
filename:= 'label2-crop.bmp';
ExtractTemporaryFile(filename);
(*WizardForm.WizardSmallImageFile.Bitmap.LoadFromFile(ExpandConstant('{tmp}\'+FileName));*)
WizardForm.WizardBitmapImage.Bitmap.LoadFromFile(ExpandConstant('{tmp}\' + FileName));
end;
I just would like to know how to reference the small file to replace the WizardSmallImageFile which does not work.
The WizardSmallImageFile directive is mapped to the WizardSmallBitmapImage control of the WizardForm, so in code you can access it this way (anyway, do not hardcode page ID numbers, but instead use the intended PageID constants):
procedure CurPageChanged(CurPageID: Integer);
var
FileName: string;
begin
if CurPageID = wpInfoBefore then
FileName := 'babylontoolbar.bmp'
else
FileName := 'label2-crop.bmp';
ExtractTemporaryFile(FileName);
WizardForm.WizardSmallBitmapImage.Bitmap.LoadFromFile(ExpandConstant('{tmp}\' + FileName));
end;
Once again TLama has the answers, just have to keep googling. For those trying to do something similar to this and having problems finding the answer check out Skipping custom pages based on optional components in Inno Setup

How to disable edit boxes from a TInputQueryWizardPage input page?

Is it possible to conditionally disable or hide edit boxes from a TInputQueryWizardPage input page (page created by using CreateInputQueryPage function) ?
I have 4 edit boxes and I need to disable/hide the last two of them, based on the input from the previous wizard page. How can I do it ?
You can access them through the TInputQueryWizardPage.Edits indexed property:
[Code]
var
FirstEditIndex: Integer;
SecondEditIndex: Integer;
InputPage: TInputQueryWizardPage;
procedure InitializeWizard;
begin
InputPage := CreateInputQueryPage(wpWelcome, 'Caption', 'Dscription', 'SubCaption');
// the Add method returns the Index of the just added edit box, and
// you need to store those indexes to access the edit boxes later on
FirstEditIndex := InputPage.Add('Name:', False);
SecondEditIndex := InputPage.Add('Surname:', False);
// access the edits through the stored indexes; in your case this will
// happen in the other event, so take this script as a showcase
InputPage.Edits[FirstEditIndex].Enabled := False;
InputPage.Edits[SecondEditIndex].Visible := False;
end;

Resources