(转)Inno Setup入门(十三)——Pascal脚本(2)

本文转载自:http://blog.csdn.net/yushanddddfenghailin/article/details/17250933

事件函数(2)

function CheckPassword(Password: String): Boolean;

如果安装程序在Pascal 脚本中发现该函数,它自动显示密码页并调用CheckPassword检查密码。返回True 表示接受密码,返回False拒绝。测试代码如下:

function CheckPassword(Password: String): Boolean;

begin

if Password='castor' then

result:=true;

end;

在安装过程中将会出现询问安装密码的页面,如果输入错误将会出现下面的对话框:

为了避免在 [Code] 段内部贮存真实的密码,最好使用其他的信息进行比较,例如使用GetMD5OfString(Password)计算实际密码的MD5值保护实际密码。

function NeedRestart(): Boolean;

如果返回True,安装程序在安装结束时提示用户重启系统,False则不提示。测试代码如下:

function NeedRestart(): Boolean;

begin

result:=True;

end;

在安装完成之后的finish页面,将会出现如下的选项:

function UpdateReadyMemo(Space, NewLine, MemoUserInfoInfo, MemoDirInfo, MemoTypeInfo, MemoComponentsInfo, MemoGroupInfo, MemoTasksInfo: String): String;

如果脚本中存在该函数,则在Ready to Install页面变为活动页的时候自动调用该函数,该函数返回一段文本,该文本显示于Ready to Install页面中的设置备注中,并且该文本将用NewLine参数分割为一个单独的多行字符串,参数Space指代空格,测试是六个,其它参数将包含安装程序用于设置段的字符(可能是空的)。例如MemoDirInfo参数包含选择目录段的字符串。测试代码如下:

function UpdateReadyMemo(Space, NewLine, MemoUserInfoInfo, MemoDirInfo, MemoTypeInfo, MemoComponentsInfo, MemoComponentsInfo, MemoTasksInfo: String): String;

var

res: String;

begin

res:='UpdateReadyMemo Function is here'+NewLine+'This is the Second Line';

res:=res+Space+'And with Six Spaces';

res:=res+NewLine+'MemoUserInfoInfo'+MemoUserInfoInfo;

res:=res+NewLine+'MemoDirInfo'+MemoDirInfo;

res:=res+NewLine+'MemoTypeInfo'+MemoTypeInfo;

res:=res+NewLine+'MemoComponentsInfo'+MemoComponentsInfo;

res:=res+NewLine+'MemoComponentsInfo'+MemoComponentsInfo;

res:=res+NewLine+'MemoTasksInfo'+MemoTasksInfo;

Result:=res;

end;

运行后在安装前会出现确认页面:

 

标记黄色文字下面是各个参数的内容。

procedure RegisterPreviousData(PreviousDataKey: Integer);

本过程实现在自定义向导页中贮存用户输入的设置,在脚本中放入本函数,并调用SetPreviousData(PreviousDataKey, ...)替换它,每次设置一个。

function CheckSerial(Serial: String): Boolean;

该函数将在用户信息向导页中自动出现一个序列号对象 (前提是[Setup]段中使用UserInfoPage=yes)。返回True表示接受序列号,返回False 拒绝。注意:当使用序列号时,该软件并没有被加密,而且Inno Setup源代码是免费获取的,有经验的人从安装程序中删除序列号保护并不是很困难的事。本函数只是方便用户在你的应用程序中仔细检查输入的序列号 (贮存在{userinfoserial}常量)。测试代码如下:

function CheckSerial(Serial: String): Boolean;

begin

if Serial='ABCDEF-1234567890' then

Result:=True;

end;

在安装过程中将会出现一个页面,如下:

如果Serial Number不正确,Next按钮将会无效,只有正确的序列号才能使得Next按钮有效,再次说明:不要指望使用这种方法保护你的软件。

function GetCustomSetupExitCode: Integer;

返回一个非零值,命令安装程序返回一个自定义退出代码,本函数只在安装程序运行完成并且退出代码已是零时才调用。常见的退出代码如下:

代码

说明

0

安装程序成功完成

1

安装程序初始化失败

2

用户在实际安装前点击取消,或者在开始的“这将安装……”时选择否

3

当准备到下一个安装阶段的时候发生致命错误,只有在比较极端的情况下发生这种错误,例如内存耗尽。

4

实际安装过程中发生致命错误

5

用户在实际安装过程中点击取消或者在“终止-重试-忽略”对话框中点击了终止

6

安装程序被调试器强制终止

7

准备安装阶段发现安装无法进行

8

准备安装阶段发现安装无法进行,并且系统需要重启来解决问题

例如在用Inno Setup调试编译后的安装文件时,按下Ctrl+F2后,下面的调试输出将会提示如下:

退出代码为6,可见安装程序被调试器强制终止。

function PrepareToInstall(var NeedsRestart: Boolean): String;

在与安装阶段返回一个非空字符串命令安装程序停止,该字符串将会作为错误消息,设置NeedsRestart为True将要求用户重启系统,该函数只在安装程序发现不能继续下去的时候才被调用。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
超强大、好用的Pascal语言释器:RemObjects Pascal Script,支持以下特性: Pascal Script is a widely-used set of components for Delphi that makes it easy to add Pascal-based scripting support to your applications, so that they can extend or control your application with custom scripts. Get Pascal Script Free Now Start using Pascal Script now and download your free copy, including full source code. Pascal Script for Delphi Pascal Script is a free scripting engine that allows you to use most of the Object Pascal language within your Delphi or Free Pascal projects at runtime. Written completely in Delphi, it is composed of a set of units that can be compiled into your executable, eliminating the need to distribute any external files. Pascal Script started out as a need for a good working script, when there were none available at the time. Why use a scripting engine? A scripting engine allows an end user to customize an application to his or her needs without having to recompile it. In addition, you can update your applications by just sending a new script file that could even be compiled to byte code, which cannot easily be transformed back to source code. Pascal Script includes the following features: Variables, Constants Standard language constructs: Begin/End If/Then/Else For/To/Downto/Do Case x Of Repeat/Until While Uses Exit Continue Break Functions inside the script Calling any external DLL function (no special function headers required) Calling registered external methods All common types like Byte, Shortint, Char, Word, SmallInt, Cardinal, Longint, Integer, String, Real, Double, Single, Extended, Boolean, Array, Record, Enumerations, Variants Allows the importing and use of classes, with events, properties, methods and constructors Allows the importing and use of interface and their members Allows IDispatch dynamic method invocation through Variant Assignment of script functions to Delphi events Uses byte code as an intermediate format and allows storing and reloading compiled scripts Easy to use component version Support for include files Support for compiler defines Capability to call RemObjects SDK Services from within scripts Pascal Script includes a tool to create headers for importing classes and interfaces
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值