Storing scripts as a resource

I have several scenarios that I would like to work with. However, I would like to know if it is possible for me to store these scripts (e.g. batch, javascript, vb scripts, etc.) in my application as a resource.

How can I do it?

+4
source share
3 answers

There are components for storing arbitrary files / files or strings in DFM

For example, there are such in rxLib / JediVCL, but I believe that many VCL libraries have one or another type of DFM Storage component.

For example, I used to store the Firebird Embedded database in DFM, to save it in TEMP and use it at runtime.

However, this is similar to manually re-reading the file in DFM every time you update it. Rather annoying to say sincerely.


Another approach is to link text to resources. You can look at DUnit sources to find out how it was done. You would also have a .rc file included in the project, so that it would be a compiler in .res when creating the .exe

This approach is fragile with regard to the interpretation of ansi / unicode text. Honestly, before I found DUnit in Delphi XE2 (it was disabled due to an IDE error), I tried to run SF vanilla DUnit. And I failed - non-unicode text files associated with the resource were completely damaged when reading with Unicode Delphi support.

Look here and there, try both approaches and choose the one that suits you best.

+1
source

You can store your scripts in resource files. But, for example, batch files must be files on disk, so you have to unpack them before you start.

+2
source

Here is a good article explaining how you can add almost anything to a resource file and compile it with your application: http://delphi.about.com/od/objectpascalide/a/embed_resources.htm

+1
source

All Articles