Including binary data making easy

classic Classic list List threaded Threaded
28 messages Options
12
Reply | Threaded
Open this post in threaded view
|

Including binary data making easy

Rainer Stratmann
Would this be possible?

// get access to the data of file.dat
// have 1 executable file with containing all the data

{$ir file.dat mydata} // include resource or similar

// fpc compiler makes this
const
 mydata : array[ 0 .. 4 ] of byte =
 ($45,$44,$63,$76,$55); // file data

// the length can find out with sizeof( mydata );

Rainer
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Including binary data making easy

Jonas Maebe-2
Rainer Stratmann wrote on ma, 23 mrt 2009:

> Would this be possible?
>
> // get access to the data of file.dat
> // have 1 executable file with containing all the data
>
> {$ir file.dat mydata} // include resource or similar
>
> // fpc compiler makes this
> const
>  mydata : array[ 0 .. 4 ] of byte =
>  ($45,$44,$63,$76,$55); // file data

FPC includes a data2inc utility that you can use for this.


Jonas

----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Including binary data making easy

Michael Van Canneyt
In reply to this post by Rainer Stratmann


On Mon, 23 Mar 2009, Rainer Stratmann wrote:

> Would this be possible?
>
> // get access to the data of file.dat
> // have 1 executable file with containing all the data
>
> {$ir file.dat mydata} // include resource or similar
>
> // fpc compiler makes this
> const
>  mydata : array[ 0 .. 4 ] of byte =
>  ($45,$44,$63,$76,$55); // file data
>
> // the length can find out with sizeof( mydata );

There are 2 fpc tools that do this for you.

bin2obj and data2inc

Michael.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Including binary data making easy

Rainer Stratmann
Am Montag, 23. März 2009 15:52 schrieb Michael Van Canneyt:

> On Mon, 23 Mar 2009, Rainer Stratmann wrote:
> > Would this be possible?
> >
> > // get access to the data of file.dat
> > // have 1 executable file with containing all the data
> >
> > {$ir file.dat mydata} // include resource or similar
> >
> > // fpc compiler makes this
> > const
> >  mydata : array[ 0 .. 4 ] of byte =
> >  ($45,$44,$63,$76,$55); // file data
> >
> > // the length can find out with sizeof( mydata );
>
> There are 2 fpc tools that do this for you.
>
> bin2obj and data2inc

Yes, but that means a step more to get the solution.
It would be much easier in the way described above.
And easy to implement so that all users get advantage of this.

Rainer

> Michael.
> _______________________________________________
> fpc-pascal maillist  -  [hidden email]
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Including binary data making easy

Michael Van Canneyt


On Mon, 23 Mar 2009, Rainer Stratmann wrote:

> Am Montag, 23. März 2009 15:52 schrieb Michael Van Canneyt:
> > On Mon, 23 Mar 2009, Rainer Stratmann wrote:
> > > Would this be possible?
> > >
> > > // get access to the data of file.dat
> > > // have 1 executable file with containing all the data
> > >
> > > {$ir file.dat mydata} // include resource or similar
> > >
> > > // fpc compiler makes this
> > > const
> > >  mydata : array[ 0 .. 4 ] of byte =
> > >  ($45,$44,$63,$76,$55); // file data
> > >
> > > // the length can find out with sizeof( mydata );
> >
> > There are 2 fpc tools that do this for you.
> >
> > bin2obj and data2inc
>
> Yes, but that means a step more to get the solution.
> It would be much easier in the way described above.
> And easy to implement so that all users get advantage of this.
You can use RCData resources, that works on all platforms.
Then you need to use LoadResource()

Michael.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Including binary data making easy

Rainer Stratmann
Am Montag, 23. März 2009 16:09 schrieb Michael Van Canneyt:

> On Mon, 23 Mar 2009, Rainer Stratmann wrote:
> > Am Montag, 23. März 2009 15:52 schrieb Michael Van Canneyt:
> > > On Mon, 23 Mar 2009, Rainer Stratmann wrote:
> > > > Would this be possible?
> > > >
> > > > // get access to the data of file.dat
> > > > // have 1 executable file with containing all the data
> > > >
> > > > {$ir file.dat mydata} // include resource or similar
> > > >
> > > > // fpc compiler makes this
> > > > const
> > > >  mydata : array[ 0 .. 4 ] of byte =
> > > >  ($45,$44,$63,$76,$55); // file data
> > > >
> > > > // the length can find out with sizeof( mydata );
> > >
> > > There are 2 fpc tools that do this for you.
> > >
> > > bin2obj and data2inc
> >
> > Yes, but that means a step more to get the solution.
> > It would be much easier in the way described above.
> > And easy to implement so that all users get advantage of this.
>
> You can use RCData resources, that works on all platforms.
> Then you need to use LoadResource()

Yes, this means also - as I understand it - that you have to make an
additional step to create the resource file.
For me it looks complicated. If a file's content is change then it can happen
that you forget to create the resource file and so on...

Rainer

> Michael.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Including binary data making easy

Graeme Geldenhuys-2
On Mon, Mar 23, 2009 at 5:35 PM, Rainer Stratmann
<[hidden email]> wrote:
>
> Yes, this means also - as I understand it - that you have to make an
> additional step to create the resource file.
> For me it looks complicated. If a file's content is change then it can happen
> that you forget to create the resource file and so on...

Ah, but you are missing the point. We are programmers. We do NOT forget! :-)

I have been using bin2obj for two years now. It works perfectly for
me, even though it's a (occasional) two step process. My application
changes more than the resource I include.


Regards,
  - Graeme -


_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Including binary data making easy

John Coppens
On Mon, 23 Mar 2009 18:22:15 +0200
Graeme Geldenhuys <[hidden email]> wrote:

> I have been using bin2obj for two years now. It works perfectly for
> me, even though it's a (occasional) two step process. My application
> changes more than the resource I include.

... and you can add the conversion into the Makefile, so the conversion
happens automatically when the data changes.

John
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Including binary data making easy

Marco van de Voort
In our previous episode, John Coppens said:
>
> > I have been using bin2obj for two years now. It works perfectly for
> > me, even though it's a (occasional) two step process. My application
> > changes more than the resource I include.
>
> ... and you can add the conversion into the Makefile, so the conversion
> happens automatically when the data changes.

Which makefile? For own projects I typically don't use any.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Including binary data making easy

Michael Van Canneyt


On Mon, 23 Mar 2009, Marco van de Voort wrote:

> In our previous episode, John Coppens said:
> >
> > > I have been using bin2obj for two years now. It works perfectly for
> > > me, even though it's a (occasional) two step process. My application
> > > changes more than the resource I include.
> >
> > ... and you can add the conversion into the Makefile, so the conversion
> > happens automatically when the data changes.
>
> Which makefile? For own projects I typically don't use any.

In Lazarus, you can create a pre-compile command that does it for you, so
you'll never forget.

Michael.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Including binary data making easy

Graeme Geldenhuys-2
In reply to this post by John Coppens
On Mon, Mar 23, 2009 at 7:14 PM, John Coppens <[hidden email]> wrote:
>
> ... and you can add the conversion into the Makefile, so the conversion
> happens automatically when the data changes.

I program for the 21st century. I don't use Makefile's - they are so 80's.   :-)
Though Lazarus does help out here... you can execute before and after
compilation actions. It's all in the Lazarus build dialogs.

Regards,
  - Graeme -


_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Including binary data making easy

Rainer Stratmann
In reply to this post by Michael Van Canneyt
Am Montag, 23. März 2009 18:18 schrieb Michael Van Canneyt:

> On Mon, 23 Mar 2009, Marco van de Voort wrote:
> > In our previous episode, John Coppens said:
> > > > I have been using bin2obj for two years now. It works perfectly for
> > > > me, even though it's a (occasional) two step process. My application
> > > > changes more than the resource I include.
> > >
> > > ... and you can add the conversion into the Makefile, so the conversion
> > > happens automatically when the data changes.
> >
> > Which makefile? For own projects I typically don't use any.
>
> In Lazarus, you can create a pre-compile command that does it for you, so
> you'll never forget.

And if you share the source-files with a friend and he compiles it on his
computer?

>
> Michael.
> _______________________________________________
> fpc-pascal maillist  -  [hidden email]
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Including binary data making easy

Michael Van Canneyt


On Mon, 23 Mar 2009, Rainer Stratmann wrote:

> Am Montag, 23. März 2009 18:18 schrieb Michael Van Canneyt:
> > On Mon, 23 Mar 2009, Marco van de Voort wrote:
> > > In our previous episode, John Coppens said:
> > > > > I have been using bin2obj for two years now. It works perfectly for
> > > > > me, even though it's a (occasional) two step process. My application
> > > > > changes more than the resource I include.
> > > >
> > > > ... and you can add the conversion into the Makefile, so the conversion
> > > > happens automatically when the data changes.
> > >
> > > Which makefile? For own projects I typically don't use any.
> >
> > In Lazarus, you can create a pre-compile command that does it for you, so
> > you'll never forget.
>
> And if you share the source-files with a friend and he compiles it on his
> computer?
The command is in the project's compiler options, and if the binary data file
is also on his PC, it will work out of the box.

Michael.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Including binary data making easy

Henry Vermaak
In reply to this post by Marco van de Voort
2009/3/23 Marco van de Voort <[hidden email]>:

> In our previous episode, John Coppens said:
>>
>> > I have been using bin2obj for two years now. It works perfectly for
>> > me, even though it's a (occasional) two step process. My application
>> > changes more than the resource I include.
>>
>> ... and you can add the conversion into the Makefile, so the conversion
>> happens automatically when the data changes.
>
> Which makefile? For own projects I typically don't use any.

is there a way to do this with fpmake?

henry
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Including binary data making easy

Rainer Stratmann
In reply to this post by Jonas Maebe-2
Am Monday 23 March 2009 15:51:24 schrieb Jonas Maebe:

> Rainer Stratmann wrote on ma, 23 mrt 2009:
> > Would this be possible?
> >
> > // get access to the data of file.dat
> > // have 1 executable file with containing all the data
> >
> > {$ir file.dat mydata} // include resource or similar
> >
> > // fpc compiler makes this
> > const
> >  mydata : array[ 0 .. 4 ] of byte =
> >  ($45,$44,$63,$76,$55); // file data
>
> FPC includes a data2inc utility that you can use for this.

http://sourceware.org/binutils/docs/as/Incbin.html#Incbin
http://sourceware.org/binutils/docs/as
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Including binary data making easy

zaher dirkey
In reply to this post by Graeme Geldenhuys-2
On Mon, Mar 23, 2009 at 6:22 PM, Graeme Geldenhuys <[hidden email]> wrote:
Ah, but you are missing the point. We are programmers. We do NOT forget! :-)

I forgot that!

Best Regards
Zaher Dirkey


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Including binary data making easy

zaher dirkey
In reply to this post by Michael Van Canneyt


On Mon, Mar 23, 2009 at 5:09 PM, Michael Van Canneyt <[hidden email]> wrote:
You can use RCData resources, that works on all platforms.
Then you need to use LoadResource()
I Like so, to have this syntax

{$r 'mysqlfile.sql' mysqlfile}
or
{$r 'mytextfile.txt' mytxtfile}

and then use LoadResource to get it, as like lfm files

Best Regards
Zaher Dirkey


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Including binary data making easy

geneb
In reply to this post by zaher dirkey
On Tue, 28 Aug 2012, Zaher Dirkey wrote:

> On Mon, Mar 23, 2009 at 6:22 PM, Graeme Geldenhuys
> <[hidden email]>wrote:
>
>> Ah, but you are missing the point. We are programmers. We do NOT forget!
>> :-)
>>
>
> I forgot that!
>
No, you mis-remembered it. :)

g.

--
Proud owner of F-15C 80-0007
http://www.f15sim.com - The only one of its kind.
http://www.diy-cockpits.org/coll - Go Collimated or Go Home.
Some people collect things for a hobby.  Geeks collect hobbies.

ScarletDME - The red hot Data Management Environment
A Multi-Value database for the masses, not the classes.
http://www.scarletdme.org - Get it _today_!

Buying desktop hardware and installing a server OS doesn't make a
server-class system any more than sitting in a puddle makes you a duck.
[Cipher in a.s.r]
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Including binary data making easy

Sven Barth-2
In reply to this post by Rainer Stratmann
On 27.08.2012 15:33, Rainer Stratmann wrote:

> Am Monday 23 March 2009 15:51:24 schrieb Jonas Maebe:
>> Rainer Stratmann wrote on ma, 23 mrt 2009:
>>> Would this be possible?
>>>
>>> // get access to the data of file.dat
>>> // have 1 executable file with containing all the data
>>>
>>> {$ir file.dat mydata} // include resource or similar
>>>
>>> // fpc compiler makes this
>>> const
>>>   mydata : array[ 0 .. 4 ] of byte =
>>>   ($45,$44,$63,$76,$55); // file data
>>
>> FPC includes a data2inc utility that you can use for this.
>
> http://sourceware.org/binutils/docs/as/Incbin.html#Incbin
> http://sourceware.org/binutils/docs/as
>

@Jonas: Is it just me or am I missing some mails here?

Regards,
Sven

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Including binary data making easy

Jonas Maebe-2

On 28 Aug 2012, at 09:03, Sven Barth wrote:

> On 27.08.2012 15:33, Rainer Stratmann wrote:
>> Am Monday 23 March 2009 15:51:24 schrieb Jonas Maebe:
>>> Rainer Stratmann wrote on ma, 23 mrt 2009:
>>>> Would this be possible?
>>>>
>>>> // get access to the data of file.dat
>>>> // have 1 executable file with containing all the data
>>>>
>>>> {$ir file.dat mydata} // include resource or similar
>>>>
>>>> // fpc compiler makes this
>>>> const
>>>>  mydata : array[ 0 .. 4 ] of byte =
>>>>  ($45,$44,$63,$76,$55); // file data
>>>
>>> FPC includes a data2inc utility that you can use for this.
>>
>> http://sourceware.org/binutils/docs/as/Incbin.html#Incbin
>> http://sourceware.org/binutils/docs/as
>>
>
> @Jonas: Is it just me or am I missing some mails here?

It's simply that some people are suddenly replying to mails from 23 March 2009 for some reason.


Jonas_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
12