Use Delphi to compile the installation program (1)
[Author: Yu wenqun: 18:01:08]
After you complete the development of an application, you also need to create a standardized installation program for the software. This is the last step in program design and is also an important step, because running the installer is usually the first step.
Many newspapers and articles have introduced how to use tools such as InstallShield to create installation programs. This method can quickly establish a common installation mode, but there are also some shortcomings in this method, for example, the installation program is generally large; the style is relatively simple; the startup mode and shortcuts cannot be controlled flexibly. In fact, the running steps of the installer are relatively fixed. We can compile the installer by ourselves. The following describes in detail how to use Delphi to compile an installation program with its own software characteristics.
There are several principles to be achieved by the installation program, such as one-time configuration, which have been described in many articles in the relevant magazine. The following describes how to write the installation program:
1. Create the program to be installed as the resource source file
Step 1: Compile the Myres. RC resource script file, which can be written in notepad.
Mydbsrc mydbsrcfile C:/resdemo/mynbdb. MDB
Mydbjet mydbjetfile C:/resdemo/mdac_typ.exe
Mydbapp mydbappfile C:/resdemo/tnbdemo.exe
7001 icon C:/resdemo/setup. ICO
Step 2: Use brcc32 to compile and generate the resource file Myres. Res.
Brcc32.exe Myres. RC
2. Compile the installer code
Step 1: add the {$ R Myres. Res} statement to the setup. DPR file to include the resource file during file compilation.
Step 2: Compile the installation background interface.
// The color gradient effect of the interface is achieved by refreshing adjacent rectangular blocks with a gradient.
// Other installation interfaces with special effects can also be implemented.
VaR I, j: integer;
DCT: trect;
Begin
Form1.windowstate: = wsmaximized;
J: = form1.width;
// Obtain the form height
For I: = 0 to 255 do
// Set a color value in RGB ().
Begin
Canvas. Brush. Color: = RGB (0, 0, 255-i );
// Specifies the stroke color of each rectangle (left, top, right, bottom)
// DCT: = rect (I * 2, 0, (I + 1) * 2, J );
DCT: = rect (0, I * 2, J, (I + 1) * 3 );
// The area of the rectangle to be painted each time
Canvas. fillrect (DCT );
Form1.canvas. textrect (DCT, 'ningbo University courseware Management System v1.0 ');
// Fill color
End;
End;
Step 3: create the working directory of the main program
// Set the directory environment and configuration file
If not directoryexists (edtdir. Text) then
// If MessageBox (getfocus, 'this directory does not exist. Do you want to create this directory? ', 'Query', 1) = idok then
Try
Forcedirectories (edtdir. Text );