home *** CD-ROM | disk | FTP | other *** search
- program AutoInst2;
-
- { ==================================================================
-
- Program: AutoInst v3.0
- Authors: David Dubois
- Zelkop Software
- Halifax, Nova Scotia
- CompuServe User I.D.: 71401,747
-
- and
-
- David Doty
- Skipjack Software
- Columbia, Maryland
- CompuServe User I.D.: 76244,1043
-
- Date last revised: 1988.05.06
-
- ==================================================================
-
- We hereby dedicate this code to the public domain. We would
- appreciate, though, if you mentioned our names if you use the unit.
-
- This program demonstrates how to write a program which will change
- the value of a typed constant in its own .EXE file. When the
- program is run again, the data will be initialized to the new
- value. No external files are necessary.
-
- Unlike version 1 of this program, this code will write to typed constants
- defined in a unit. Unlike version 2, the routine to write to the
- executable is in a unit and the routine will find the name and path of the
- executable- no fixed file name or assumptions about the path!
-
- The code shown here is designed for Turbo Pascal version 4.0.
- There is a simpler method available for Turbo 3.0.
-
- For this example writes a certain string a certain number of times. It
- then prompts the user for a new string and a new number. The .EXE file is
- updated to reflect the values entered by the user. The next time the
- program is run, the new values are used.
-
- USES
-
- Examples of the usefulness of this technique would be:
-
- o A program that allows the user to change default display colors.
-
- o A program that keeps track of a password that the user can change.
-
- HOW TO USE THIS TECHNIQUE
-
- Place the WritExec unit in the USES statement of the program or unit that
- needs to write the constant and make the appropriate call to
- WriteToExecutable.
-
- HOW IT WORKS
-
- See the source for the WritExec unit for a detailed description of the
- technique. Note that this technique will only work for typed constants,
- and the unit will only work under DOS 3.1 or higher (in order to find the
- name and path of the executable, the unit relies on DOS storing this after
- the environment, which only happens under DOS 3.X).
-
- ERROR CHECKING
-
- The unit does some basic error checking (of the IOResult function), and
- returns an error code if something went wrong.
-
- LIMITATIONS
-
- You cannot use MicroSoft's EXEPACK on the .EXE file, or any other
- packing method I know of. This may change the position, or even
- the size of the typed constant in the file image.
-
-
- ==================================================================}
-
- uses WritExec;
-
- type
- InstallBlockType = record
- TheNumber : integer;
- TheString : string;
- end;
-
- const
- InstallBlock : InstallBlockType
-
- = ( TheNumber : 3;
- TheString : 'Greetings from Zelkop Software' );
-
- var
- I : integer;
- begin
- with InstallBlock do
- begin
-
- { write out old data }
-
- for I := 1 to TheNumber do
- writeln ( TheString );
-
- { read in new data }
-
- write ( 'Enter TheNumber: ' );
- readln ( TheNumber );
- write ( 'Enter TheString: ' );
- readln ( TheString );
- end;
-
- { update .EXE file }
-
- if WriteToExecutable( InstallBlock, SizeOf( InstallBlock ) ) <> 0
- then writeln( 'Error writing to executable file' )
- else writeln( 'New values written to executable file' );
-
- writeln ( 'Now run this program again.' );
- end.
-