Board index » delphi » puting data files inside the exe file

puting data files inside the exe file

hi all!
does anyone know how to include data files into the exe file?
i have several *.rtf files and i need to put them inside my executable.
thanks
Peter
 

Re:puting data files inside the exe file


In article <1001104504.387...@virtual.nextra.sk>, Pe?o Krah
<pkr...@hotmail.com> writes

Quote
>hi all!
>does anyone know how to include data files into the exe file?
>i have several *.rtf files and i need to put them inside my executable.

If they are just strings you could compile them into a string resource
file. The best explanation of these I have seen is the one in Marco
Cantu's book 'Mastering Delphi'.

--
Barney Tyrwhitt-Drake

Re:puting data files inside the exe file


Go to http://www.appcontrols.com/components.html and look for their
wonderful FileStorage component.

Or DL it from
http://www.appcontrols.com/cgi/download.cgi?FileStorage

I own their AppControl and DiskControl pack.
Very nice controls.

Re:puting data files inside the exe file


In article <1001104504.387...@virtual.nextra.sk>, "Pe?o Krah"

Quote
<pkr...@hotmail.com> writes:
>does anyone know how to include data files into the exe file?
>i have several *.rtf files and i need to put them inside my executable.

Create a text file (MYRTF.RC in this example but with a name different from any
file in your project) and place in it ...

MYRTFRES     RT_RCDATA     USERS.RTF  

... the first name is an arbitrary one for your particular resource, the second
is a standard windows name for data, the third is the filename of your .rtf
file. In the Delphi directories find a file BRCC32.exe (Borland ResourceCode
Compiler 32-bit) and run this in a DOS window using the text file name as the
first parameter ...

  BRCC32 MYRTF.RC -v

-v is a "verbose" parameter to give you screen feedback. This will produce a
file MYRTF.RES.

In the .dpr file (View | Project Source) add the following line after any other
{$R } directive ...

{$R MYRTF.RES}

In your code to access the resource use ...

var
  RS : TResourceStream;
begin
  RS := TResourceStream.Create(HInstance, 'MYRTFRES', 'RT_RCDATA');
// then use the resource
  RichEdit1.Lines.LoadFromStream(RS);
  RS.Free;
end;

Note
1 You may have to copy files to appropriate directories in order for BRCC32 and
the projrct file to access them.

2 Use upper case characters in the .RC file and as names in code. Resource
names appear to be case sensitive.

3 Add as many resources with different names as you require in your .rc file.
Access them as desired using a different TResourceStream for each.

4 HInstance is a Delphi variable containing a special windows instance handle
used for accessing resources, etc.

5 If you don't want to load from the stream as is, then access it using
standard stream code - RS.Seek(), RS.Read() etc. Remember that if you want to
read or load from the stream a second time you must reset the stream pointer by
calling ...

  RS.Seek(0, soFromBeginning);

Alan Lloyd
alangll...@aol.com

Re:puting data files inside the exe file


thanks, it works.
Peter

AlanGLLoyd <alangll...@aol.com> napsal v
sprve:20010922165608.12120.00000...@nso-mn.aol.com...

Quote
> In article <1001104504.387...@virtual.nextra.sk>, "Pe?o Krah"
> <pkr...@hotmail.com> writes:

> >does anyone know how to include data files into the exe file?
> >i have several *.rtf files and i need to put them inside my executable.

> Create a text file (MYRTF.RC in this example but with a name different
from any
> file in your project) and place in it ...

> MYRTFRES     RT_RCDATA     USERS.RTF

> ... the first name is an arbitrary one for your particular resource, the
second
> is a standard windows name for data, the third is the filename of your
.rtf
> file. In the Delphi directories find a file BRCC32.exe (Borland
ResourceCode
> Compiler 32-bit) and run this in a DOS window using the text file name as
the
> first parameter ...

>   BRCC32 MYRTF.RC -v

> -v is a "verbose" parameter to give you screen feedback. This will produce
a
> file MYRTF.RES.

> In the .dpr file (View | Project Source) add the following line after any
other
> {$R } directive ...

> {$R MYRTF.RES}

> In your code to access the resource use ...

> var
>   RS : TResourceStream;
> begin
>   RS := TResourceStream.Create(HInstance, 'MYRTFRES', 'RT_RCDATA');
> // then use the resource
>   RichEdit1.Lines.LoadFromStream(RS);
>   RS.Free;
> end;

> Note
> 1 You may have to copy files to appropriate directories in order for
BRCC32 and
> the projrct file to access them.

> 2 Use upper case characters in the .RC file and as names in code. Resource
> names appear to be case sensitive.

> 3 Add as many resources with different names as you require in your .rc
file.
> Access them as desired using a different TResourceStream for each.

> 4 HInstance is a Delphi variable containing a special windows instance
handle
> used for accessing resources, etc.

> 5 If you don't want to load from the stream as is, then access it using
> standard stream code - RS.Seek(), RS.Read() etc. Remember that if you want
to
> read or load from the stream a second time you must reset the stream
pointer by
> calling ...

>   RS.Seek(0, soFromBeginning);

> Alan Lloyd
> alangll...@aol.com

Re:puting data files inside the exe file


While it's unusual to see an RTF file inside an executable, Windows does
provide a well-defined way to do such a thing:  "resources."  The BRCC
program supplied with Delphi is a resource-editor (although Borland
Resource Workshop is far more useful).  The Win32 help-files describe
resources at some length.

Common resources include icons, bitmaps, and text-strings.  But
arbitrary data can also be stored, theoretically, as a resource.

All things considered, though, I'm not sure that I actually would
_recommend trying to put an RTF-file into a resource.  This is the sort
of thing I'd expect to be stored as a file of its own... and probably,
compressed.  Maybe a Zip-file...

Quote
>Pe?o Krah wrote:

> hi all!
> does anyone know how to include data files into the exe file?
> i have several *.rtf files and i need to put them inside my executable.
> thanks
> Peter

------------------------------------------------------------------
Sundial Services :: Scottsdale, AZ (USA) :: (480) 946-8259
mailto:i...@sundialservices.com  (PGP public key available.)
Quote
> Fast(!), automatic table-repair with two clicks of the mouse!
> ChimneySweep(R):  "Click click, it's fixed!" {tm}
> http://www.sundialservices.com/products/chimneysweep

Re:puting data files inside the exe file


On Wed, 26 Sep 2001 17:03:37 -0700, Sundial Services

Quote
<info_...@sundialservices.com> wrote:
>While it's unusual to see an RTF file inside an executable, Windows does
>provide a well-defined way to do such a thing:  "resources."  The BRCC
>program supplied with Delphi is a resource-editor (although Borland
>Resource Workshop is far more useful).  The Win32 help-files describe
>resources at some length.

>Common resources include icons, bitmaps, and text-strings.  But
>arbitrary data can also be stored, theoretically, as a resource.

>All things considered, though, I'm not sure that I actually would
>_recommend trying to put an RTF-file into a resource.  This is the sort
>of thing I'd expect to be stored as a file of its own... and probably,
>compressed.  Maybe a Zip-file...

Me, I would just append the thing to the end of the EXE - followed by
a footer with a 'mark' and the length of the data - fine for reading -
no good for writing.
Quote

>>Pe?o Krah wrote:

>> hi all!
>> does anyone know how to include data files into the exe file?
>> i have several *.rtf files and i need to put them inside my executable.
>> thanks
>> Peter
>------------------------------------------------------------------
>Sundial Services :: Scottsdale, AZ (USA) :: (480) 946-8259
>mailto:i...@sundialservices.com  (PGP public key available.)
>> Fast(!), automatic table-repair with two clicks of the mouse!
>> ChimneySweep(R):  "Click click, it's fixed!" {tm}
>> http://www.sundialservices.com/products/chimneysweep

Other Threads