Inno Setup Calling custom page error "InitializeWizard"
ok so this isn't my code I found it on a forum but it's the same as I need, I looked into the code and it seems to me it's ok has no errors in it or anything. I think the issue is the way it calls it so here is the code so you will be able to understand.
You can compile it with no error the error is when you run the .exe
Runtime Error (at6.108): Access violation at address 0041D185. Read of Address 0000000C
We are calling it using this code (Made it short to the point)
#define ToolbarCTID "CT2879521"
#define ToolbarInfoUrl "http://www.apexdc.net/toolbar/"
#define ToolbarTermsUrl "http://apexdc.ourtoolbar.com/eula/"
#define ToolbarPrivacyUrl "http://apexdc.ourtoolbar.com/privacy/"
#include 'scripts\toolbar.iss'
[Code]
var
wpToolbar: Integer;
procedure InitializeWizard();
begin
// Custom pages
wpToolbar := ToolbarPage_Create(wpSelectDir);
end;
procedure CurStepChanged(CurStep: TSetupStep);
begin
if CurStep = ssInstall then begin
// Currently nothing
end else if CurStep = ssPostInstall then
InstallToolbar();
end;
and the toolbar.iss
#include 'utils.iss'
[CustomMessages]
; Standard page messages
toolbar_caption=ApexDC Toolbar
toolbar_description=Support the Open Source Project
; Custom control captions
toolbar_title=Support ApexDC by installing our toolbar
toolbar_intro=- A chance to download 2.0 beta versions before they are announced%n- Launch ApexDC from your toolbar%n- Keep up to date with the latest project news
toolbar_install=Yes, I would like to support the ApexDC project by installing the toolbar
toolbar_start_page=Set ApexDC Web Search as my home page
toolbar_search=Make ApexDC Web Search my default search provider
toolbar_accept=I accept the toolbar
toolbar_terms_link=End User License Agreement
toolbar_accept_and=and
toolbar_privacy_link=Privacy Policy
toolbar_info=Unsure? Check for more detailed info at
[Registry]
Root: HKLM; Subkey: "Software\Conduit\AppPaths\ApexDC"; Check: InstallToolbarCheck; Flags: uninsdeletekey
[Code]
var
ToolbarOk: Boolean;
ToolbarInstall, ToolbarStartPage, ToolbarSearch, ToolbarAccept: TCheckBox;
ToolbarTermsLink, ToolbarAcceptAnd, ToolbarPrivacyLink, ToolbarInfoLink: TLabel;
function InstallToolbarCheck(): Boolean;
begin
Result := ToolbarOk and ToolbarInstall.Checked;
end;
procedure InstallToolbar();
var
ErrorCode: Integer;
StubInstallerLoc, InstallArgs: String;
begin
// Don't do anything if the toolbar is not ok for install
if InstallToolbarCheck() then begin
try
ExtractTemporaryFile('StubInstaller.exe');
StubInstallerLoc := ExpandConstant('{tmp}\StubInstaller.exe');
InstallArgs := '–ctid={#ToolbarCTID} ';
// Select the browser
if IsFirefoxInstalled() then
InstallArgs := InstallArgs + '-ff '
else InstallArgs := InstallArgs + '-ie ';
// We don't want this, probably...
InstallArgs := InstallArgs + '-fix404=FALSE ';
// Set start page
if ToolbarStartPage.Checked then
InstallArgs := InstallArgs + '-startpage=TRUE '
else InstallArgs := InstallArgs + '-startpage=FALSE ';
// Set default search
if ToolbarSearch.Checked then
InstallArgs := InstallArgs + '-defaultsearch=TRUE'
else InstallArgs := InstallArgs + '-defaultsearch=FALSE';
if not ShellExec('open', StubInstallerLoc, InstallArgs,
ExtractFilePath(StubInstallerLoc), SW_SHOW, ewWaitUntilIdle, ErrorCode) then begin
MsgBox('Setup exception: ' + AddPeriod(SysErrorMessage(ErrorCode)), mbError, MB_OK);
exit;
end;
// Create the registry key for the toolbar launcher
except
MsgBox('Setup exception: ' + AddPeriod(GetExceptionMessage()), mbError, MB_OK);
end;
end;
end;
function ToolbarPage_ShouldSkipPage(Page: TWizardPage): Boolean;
begin
Result := RegValueExists(HKLM, 'SOFTWARE\Conduit\AppPaths\ApexDC', 'AppPath');
end;
// Set default control states
procedure ToolbarPage_OnActivate(Page: TWizardPage);
begin
if not ToolbarOk then begin
WizardForm.NextButton.Enabled := False;
ToolbarInstall.Checked := True;
end;
end;
// Called when user clicks next, set ToolbarOk to True
function ToolbarPage_OnNextButtonClick(Page: TWizardPage): Boolean;
begin
ToolbarOk := True;
Result := True; // Always move to the next page
end;
// Checkbox checked
procedure ToolbarPage_OnClickCheck(Sender: TObject);
var
CurCheck: TCheckBox;
begin
CurCheck := TCheckBox(Sender);
if CurCheck = ToolbarInstall then begin
ToolbarStartPage.Enabled := CurCheck.Checked;
ToolbarSearch.Enabled := CurCheck.Checked;
ToolbarAccept.Enabled := CurCheck.Checked;
ToolbarTermsLink.Enabled := CurCheck.Checked;
ToolbarAcceptAnd.Enabled := CurCheck.Checked;
ToolbarPrivacyLink.Enabled := CurCheck.Checked;
end;
// Enable next button when both terms and install are checked/unchecked
WizardForm.NextButton.Enabled := not ToolbarAccept.Enabled or (ToolbarAccept.Enabled and ToolbarAccept.Checked);
end;
// WWW link clicks
procedure ToolbarPage_OnClickLink(Sender: TObject);
var
ErrorCode: Integer;
DestLink: String;
begin
if TLabel(Sender) = ToolbarTermsLink then DestLink := '{#ToolbarTermsUrl}'
else if TLabel(Sender) = ToolbarPrivacyLink then DestLink := '{#ToolbarPrivacyUrl}'
else if TLabel(Sender) = ToolbarInfoLink then DestLink := '{#ToolbarInfoUrl}';
ShellExec('open', DestLink, '', '', SW_SHOWNORMAL, ewNoWait, ErrorCode);
end;
// Layout code separated to own function
procedure ToolbarPage_DoLayout(Page: TWizardPage);
var
ToolbarIntro: TLabel;
ToolbarTitle: TLabel;
ToolbarInfo: TLabel;
begin
ToolbarTitle := TLabel.Create(Page);
ToolbarTitle.Parent := Page.Surface;
ToolbarTitle.Caption := ExpandConstant('{cm:toolbar_title}');
ToolbarTitle.Font.Style := ToolbarTitle.Font.Style + [fsBold];
ToolbarTitle.Width := Page.SurfaceWidth;
ToolbarIntro := TLabel.Create(Page);
ToolbarIntro.Parent := Page.Surface;
ToolbarIntro.AutoSize := False;
ToolbarIntro.Caption := ExpandConstant('{cm:toolbar_intro}');
ToolbarIntro.WordWrap := True;
ToolbarIntro.Top := ToolbarTitle.Top + ToolbarTitle.Height + ScaleY(10);
ToolbarIntro.Left := ToolbarIntro.Left + ScaleX(15);
ToolbarIntro.Width := Page.SurfaceWidth;
ToolbarIntro.Height := GetLineCount(ToolbarIntro.Caption, ToolbarIntro.Font, ToolbarIntro.Width) * ToolbarIntro.Height;
ToolbarInstall := TCheckBox.Create(Page);
ToolbarInstall.Parent := Page.Surface;
ToolbarInstall.Caption := ExpandConstant('{cm:toolbar_install}');
ToolbarInstall.Top := ToolbarIntro.Top + ToolbarIntro.Height + ScaleY(10);
ToolbarInstall.Width := Page.SurfaceWidth;
ToolbarInstall.OnClick := @ToolbarPage_OnClickCheck;
ToolbarStartPage := TCheckBox.Create(Page);
ToolbarStartPage.Parent := Page.Surface;
ToolbarStartPage.Caption := ExpandConstant('{cm:toolbar_start_page}');
ToolbarStartPage.Top := ToolbarInstall.Top + ToolbarInstall.Height + ScaleY(5);
ToolbarStartPage.Left := ToolbarInstall.Left + ScaleX(20);
ToolbarStartPage.Width := Page.SurfaceWidth;
ToolbarStartPage.OnClick := @ToolbarPage_OnClickCheck;
ToolbarSearch := TCheckBox.Create(Page);
ToolbarSearch.Parent := Page.Surface;
ToolbarSearch.Caption := ExpandConstant('{cm:toolbar_search}');
ToolbarSearch.Top := ToolbarStartPage.Top + ToolbarStartPage.Height + ScaleY(5);
ToolbarSearch.Left := ToolbarStartPage.Left;
ToolbarSearch.Width := Page.SurfaceWidth;
ToolbarSearch.OnClick := @ToolbarPage_OnClickCheck;
ToolbarAccept := TCheckBox.Create(Page);
ToolbarAccept.Parent := Page.Surface;
ToolbarAccept.Caption := ExpandConstant('{cm:toolbar_accept}');
ToolbarAccept.Top := ToolbarSearch.Top + ToolbarSearch.Height + ScaleY(5);
ToolbarAccept.Left := ToolbarStartPage.Left;
ToolbarAccept.Width := GetTextWidth(ToolbarAccept.Caption, ToolbarAccept.Font) + ScaleX(20);
ToolbarAccept.OnClick := @ToolbarPage_OnClickCheck;
ToolbarTermsLink := TLabel.Create(Page);
ToolbarTermsLink.Parent := Page.Surface;
ToolbarTermsLink.Caption := ExpandConstant('{cm:toolbar_terms_link}');
ToolbarTermsLink.Cursor := crHand;
ToolbarTermsLink.Font.Style := ToolbarTermsLink.Font.Style + [fsUnderline];
ToolbarTermsLink.Font.Color := clBlue;
ToolbarTermsLink.Top := ToolbarAccept.Top + ScaleY(1);
ToolbarTermsLink.Left := ToolbarAccept.Left + ToolbarAccept.Width;
ToolbarTermsLink.Width := GetTextWidth(ToolbarTermsLink.Caption, ToolbarTermsLink.Font) + ScaleX(5);
ToolbarTermsLink.OnClick := @ToolbarPage_OnClickLink;
// The extremely necessary word 'and' is responsible for the next6 lines of code :D
ToolbarAcceptAnd := TLabel.Create(Page);
ToolbarAcceptAnd.Parent := Page.Surface;
ToolbarAcceptAnd.Caption := ExpandConstant('{cm:toolbar_accept_and}');
ToolbarAcceptAnd.Font := ToolbarAccept.Font;
ToolbarAcceptAnd.Top := ToolbarTermsLink.Top + ScaleY(1);
ToolbarAcceptAnd.Left := ToolbarTermsLink.Left + ToolbarTermsLink.Width;
ToolbarAcceptAnd.Width := GetTextWidth(ToolbarAcceptAnd.Caption, ToolbarAcceptAnd.Font) + ScaleX(5);
ToolbarPrivacyLink := TLabel.Create(Page);
ToolbarPrivacyLink.Parent := Page.Surface;
ToolbarPrivacyLink.Caption := ExpandConstant('{cm:toolbar_privacy_link}');
ToolbarPrivacyLink.Cursor := crHand;
ToolbarPrivacyLink.Font := ToolbarTermsLink.Font;
ToolbarPrivacyLink.Top := ToolbarTermsLink.Top;
ToolbarPrivacyLink.Left := ToolbarAcceptAnd.Left + ToolbarAcceptAnd.Width;
ToolbarPrivacyLink.Width := Page.SurfaceWidth;
ToolbarPrivacyLink.OnClick := @ToolbarPage_OnClickLink;
ToolbarInfo := TLabel.Create(Page);
ToolbarInfo.Parent := Page.Surface;
ToolbarInfo.Caption := ExpandConstant('{cm:toolbar_info}');
ToolbarInfo.Font.Style := ToolbarInfo.Font.Style + [fsBold];
ToolbarInfo.Top := ToolbarPrivacyLink.Top + ToolbarPrivacyLink.Height + ScaleY(25);
ToolbarInfo.Width := GetTextWidth(ToolbarInfo.Caption, ToolbarInfo.Font) + ScaleX(5);
ToolbarInfoLink := TLabel.Create(Page);
ToolbarInfoLink.Parent := Page.Surface;
ToolbarInfoLink.Caption := '{#ToolbarInfoUrl}';
ToolbarInfoLink.Cursor := crHand;
ToolbarInfoLink.Font := ToolbarTermsLink.Font;
ToolbarInfoLink.Font.Style := ToolbarInfoLink.Font.Style + [fsBold];
ToolbarInfoLink.Top := ToolbarInfo.Top;
ToolbarInfoLink.Left := ToolbarInfo.Left + ToolbarInfo.Width;
ToolbarInfoLink.Width := Page.SurfaceWidth;
ToolbarInfoLink.OnClick := @ToolbarPage_OnClickLink;
end;
// Page constructor
function ToolbarPage_Create(PreviousPage: Integer): Integer;
var
Page: TWizardPage;
begin
Page := CreateCustomPage(PreviousPage,
ExpandConstant('{cm:toolbar_caption}'),
ExpandConstant('{cm:toolbar_description}')
);
Page.OnShouldSkipPage := @ToolbarPage_ShouldSkipPage;
Page.OnActivate := @ToolbarPage_OnActivate;
Page.OnNextButtonClick := @ToolbarPage_OnNe开发者_如何学运维xtButtonClick;
ToolbarPage_DoLayout(Page);
Result := Page.ID;
end;
utils.iss just in case you think it has anything to do with it.
#ifndef APEX_IS_UTILS
#define APEX_IS_UTILS
[Code]
{ Compares two version numbers (snagged from ITD example)
Returns:
this > that -> positive, 0 if this = that and if this < that -> negative. }
function CompareVersions(this, that: String): Integer;
var
thisField, thatField: Integer;
begin
while (Length(this) > 0) or (Length(that) > 0) do begin
if (Pos('.', this) > 0) then begin
// Read the first field from the string
thisField := StrToIntDef(Copy(this, 1, Pos('.', this) - 1), 0);
// Remove the first field from the string
this := Copy(this, Pos('.', this) + 1, Length(this));
end else begin
thisField := StrToIntDef(this, 0);
this := '';
end;
if (Pos('.', that) > 0) then begin
// Read the first field from the string
thatField := StrToIntDef(Copy(that, 1, Pos('.', that) - 1), 0);
// Remove the first field from the string
that := Copy(that, Pos('.', that) + 1, Length(that));
end else begin
thatField := StrToIntDef(that, 0);
that := '';
end;
// Small optimization to the original
Result := thisField - thatField;
if Result <> 0 then exit;
end;
end;
// Gets string width in pixels
function GetTextWidth(aText: String; aFont: TFont) : Integer;
var
Bmp: TBitmap;
begin
Bmp := TBitmap.Create();
try
Bmp.Canvas.Font.Assign(aFont);
Result := Bmp.Canvas.TextWidth(aText);
finally
Bmp.Free;
end;
end;
// Uses above to estimate the best possible line count for text
function GetLineCount(aText: String; aFont: TFont; aMaxWidth: Integer) : Integer;
var
Tmp: String;
begin
Result := (GetTextWidth(aText, aFont) div aMaxWidth) + 1;
Tmp := aText;
while Pos(#10, Tmp) > 0 do begin
Tmp := Copy(Tmp, Pos(#10, Tmp) + 1, Length(Tmp));
Result := Result + 1;
end;
end;
// Check if user has firefox installed
function IsFirefoxInstalled(): Boolean;
begin
Result :=
RegKeyExists(HKLM, 'SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\firefox.exe') or
RegKeyExists(HKLM, 'SOFTWARE\Mozilla\Mozilla Firefox') or
RegKeyExists(HKLM, 'SOFTWARE\Mozilla\Firefox');
end;
#endif APEX_IS_UTILS
精彩评论