[Home] [Puzzles & Projects] [Delphi Techniques] [Math Topics] [Library] [Utilities]
There are situations where it would be convenient to incorporate a text file into the executable module of a program. Doing so eliminates the chance that the text file would be accidentally deleted or modified. This program, StringListToResource, implements this ability by converting a text file to "resource" file. The resource file may be embedded into the program at link time and converted back to a string list by some simple code changes within the program.
Background & Techniques
Twice in recent weeks I have had occasion to work on programs which meet the conditions described above: requiring a fixed text file be read into the program each time it is executed. One is Translations which helps translate program text to languages other than English. It reads a file, "ISO639V1.txt", which provides language names associated with the nearly 200 two-letter language code identifiers defined by ISO standard 639.1. The other program is KeyCodes which displays the names associated with scan-codes generated when keyboard keys are pressed. Text file "VKeys.txt" defines those associations.
Both of the text files listed above are included as samples in this distribution. In order to embed a text file as a resource we need to compile a resource script using the Borland Resource Compiler, brcc32,exe. This is a somewhat ancient DOS command line program making its usage somewhat inconvenient. Our program:
The name of the selected text file becomes the base file name for the resource script file and the compiled resource file with the ".txt" text file extension replaced by ".rc" and ".res" respectively.
I have not yet figured out how to redirect any output messages from the resource compiler back to my program, so i settled for making sure that a new .res file is built before declaring success. All I can recommend for now is to revert to using CMD to run brcc32.exe if problems arise.
Once the RES file is built, we still need to retrieve it with the using program, Rather than describing it here, refer to the KeyCodes program to see how to it was accomplished.
Suggestions for Further Explorations
Copyright © 2000-2013, Gary Darby
All rights reserved.