The easiest way I know to include external
files into an EXE is to add a myapp.rc file to your
project.
A
sample of one of my .rc files is listed below.
/////////////////////////////////////////////////////////////////////////////
touchStone_dot_mdb
files DISCARDABLE
"touchStone.mdb"
toolbar_names files DISCARDABLE "..\images\toolbar.txt" sourcesafe_tick icon DISCARDABLE "..\images\sourcesafe_tick.ico" sourcesafe_cross icon DISCARDABLE "..\images\sourcesafe_cross.ico" toolbar20_mono bitmap DISCARDABLE "..\images\SHDOCVW_DLL_Bitmap_272.bmp" toolbar20_color bitmap DISCARDABLE "..\images\SHDOCVW_DLL_Bitmap_273.bmp" toolbar16_mono bitmap DISCARDABLE "..\images\SHDOCVW_DLL_Bitmap_274.bmp" toolbar16_color bitmap DISCARDABLE "..\images\SHDOCVW_DLL_Bitmap_275.bmp" toolbar20_monox bitmap DISCARDABLE "..\images\SHDOCVW_DLL_Bitmap_276.bmp" toolbar20_colorx bitmap DISCARDABLE "..\images\SHDOCVW_DLL_Bitmap_277.bmp" /////////////////////////////////////////////////////////////////////////////
The
column on the left is the resource name and their are various loadfromresource
methods that can be used.
My
Touchstone application requires a Touchstone.mdb file so I will use the function
below to make sure it exisits and
if not
create it with the resource. No compression I'm afraid, but then I'm
lazy.
procedure checkFileExists(const
fname:string;resourcename:string);
var stmRes :TResourcestream; stmFile :TFileStream; dotPos :integer; begin try if not fileexists(fname) then begin if resourcename='' then resourcename := fname; dotPos := pos('.',resourcename); if dotPos >0 then resourcename := copy(resourcename,1,dotPos-1)+'_dot_'+copy(resourcename,dotPos+1,100); stmRes := Tresourcestream.create(Hinstance,resourcename,'FILES'); stmFile := Tfilestream.Create(fname,fmCreate); stmFile.CopyFrom(stmRes,0); stmRes.Free; stmFile.free; showmessage(fname + ' has been created.'); end except on E:exception do begin if assigned(stmRes) then stmRes.free; if assigned(stmFile) then stmFile.free; e.message := e.message + ^J^M + ' in checkfileexists(' + fname + ')'; raise; end; end; {of try} end; {of checkFileExists}
|
- [DUG]: resources Steven Wild
- RE: [DUG]: resources Patrick Dunford
- RE: [DUG]: resources Patrick Dunford
- RE: [DUG]: resources Chris Reynolds
- RE: [DUG]: resources Nahum Wild