{~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~} { Downloaded from The Coder's Knowledge Base } { http://www.netalive.org/ckb/ } {~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~} { @ CKB Header Version.: 1.01 } { @ Category ID........: delphi_misc } { @ Added to database..: 14.10.98 } {~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~} { @ Title..............: Data in executable } { @ Original Filename..: DataInExe.txt } { @ Author.............: Peter Below } { @ Description........: How to include and retrieve data in/from exe } { @ Tested w. Compiler.: not tested yet } { @ Submitted by.......: Mike Orriss (mjo@3kcc.co.uk) } {~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~} You can include any kind of data as a RCDATA or user type resource. This is very simple. The following is from a message on a related item and should show you the general technique. Type TStrItem = String[39]; { 39 characters + length byte -> 40 bytes } TDataArray= Array [0..7, 0..24] of TStrItem; Const Data : TDataArray = ( ('..', ...., '..' ), { 25 strings per row } ... { 8 of these rows } ('..', ...., '..' )); { 25 strings per row } The data will end up in your data segment and consume 8K of it. If that is too much for you, put the actual data into a RCDATA resource. For that you proceed like this. Write a small windowless program that declares the typed constant as above and does nothing more than write it to a disk file: Program MakeData; Type TStrItem = String[39]; { 39 characters 0 length byte -> 40 bytes } TDataArray= Array [0..7, 0..24] of TStrItem; Const Data : TDataArray = ( ('..', ...., '..' ), { 25 strings per row } ... { 8 of these rows } ('..', ...., '..' )); { 25 strings per row } Var F: File of TDataArray; Begin Assign( F, 'data.dat' ); Rewrite(F); Write(F, Data); Close(F); End. Now prepare a resource file, lets call it DATA.RC. It contains only the following line: DATAARRAY RCDATA "data.dat" Save it, open a DOS box, change to the directory you saved data.rc to (same as data.dat is in!), run the following command: brcc data.rc (brcc32 for Delphi 2.0) That gives you a data.res file you can now include in your Delphi project. At runtime you can now generate a pointer to that resource data and access it as needed. { in a Unit interface section } Type TStrItem = String[39]; { 39 characters + length byte -> 40 bytes } TDataArray= Array [0..7, 0..24] of TStrItem; PDataArray= ^TDataArray; Const pData: PDataArray = Nil; { use a Var in Delphi 2.0} Implementation {$R DATA.RES} Procedure LoadDataResource; Var dHandle: THandle; Begin { pData := Nil; if pData is a Var } dHandle := FindResource( hInstance, 'DATAARRAY' , RT_RCDATA ); If dHandle <> 0 Then Begin dhandle := LoadResource( hInstance, dHandle ); If dHandle <> 0 Then pData := LockResource( dHandle ); End; If pData = Nil Then { failed, issue appropriate error message, use WinProcs.MessageBox, not VCL stuff, since the code here will execute as part of the program startup sequence and VCL may not have initialized yet! } End; Initialization LoadDataResource; End. Now you can refer to items in the array with pData^[i,j]-syntax. - Peter Below