Writing quick Pascal programs with Inno Setup

From ISXKB

Jump to: navigation, search

Contents

Introduction

Are you familiar with Pascal but short of a proper development environment? Maybe you only need a quick and dirty solution for a few lines of code.

Some people might not like the idea but you can "abuse" Inno Setup for this purpose.

'Hello World' with Inno Setup

InitializeSetup () is the event function which is called on start-up of an Inno Setup installation program.

Excerpt from the help file:

procedure InitializeSetup();
Called during Setup's initialization. Return False to abort Setup, True otherwise.

So, in theory, all that's needed are the following few lines of code:

[Code]
function InitializeSetup(): Boolean;
begin
	MsgBox('Hello world.', mbInformation, MB_OK);
	Result := FALSE;
end;

If you try to compile these lines a compiler error shows up. You can fix this error, and after fixing a few more errors it turns out that the following minimum [Setup] section is required:

[Setup]
AppName=EmptyProgram
AppVerName=EmptyProgram 1x
DefaultDirName={pf}\EmptyProgram

Should the 'Result := FALSE;' be forgotten accidentally in the InitializeSetup () function the installation could run through and leave a removable application entry in the 'Add/Remove Programs' of the Windows Control Panel. Extending the [Setup] section by

UsePreviousAppDir=false
Uninstallable=false

makes it much safer.

Setup Hello World

Although it doesn't look bad yet, there's still room for improvements (see the picture on the right). The text 'Setup' in the title bar still gives it the taste of a setup.

A quick look in the file 'Default.isl' uncovers this message:

SetupAppTitle=Setup

'Default.isl' is located in the folder where Inno Setup has been installed, usually 'C:\Program Files\Inno Setup 5' on English systems.

Maybe the output file name 'setup.exe' doesn't sound too good either, but this can easily be changed:

OutputBaseFilename=HelloWorld

Now the executable's name is 'HelloWorld.exe'.

Another thing is that Inno Setup defaults to 'PrivilegesRequired=admin' in the [Setup] section if not changed explicitely. If a user ran the program it would be only allowed for administrators.

PrivilegesRequired=none

The real 'Hello World' with Inno Setup

After changing the Inno Setup script accordingly the outcome is a real 'Hello World' application:

Hello World
[Setup]
AppName=EmptyProgram
AppVerName=EmptyProgram 1
UsePreviousAppDir=false
DefaultDirName={pf}\EmptyProgram
Uninstallable=false
OutputBaseFilename=HelloWorld
PrivilegesRequired=none

[Messages]
SetupAppTitle=My Title

[Code]
function InitializeSetup(): Boolean;
begin
	MsgBox('Hello world.', mbInformation, MB_OK);
	Result := FALSE;
end;

Summary

All in all, that's a quick way of writing small Pascal programs.

Of course, there's not many solutions that don't have any drawbacks as well.

The above 'Hello World' application uses almost 300 kB on disk. On the other hand, it doesn't require any runtime environments or DLLs to be installed or even registered. It does beat a compiled AutoIt script, though. Compared to Java, Visual Basic or .Net applications it's a dwarf anyway.

See also

External links

Personal tools
Ads: