Lazarus

Programming => Packages and Libraries => Ported from Delphi/Kylix => Topic started by: Keneto on July 13, 2006, 02:17:35 am

Title: Resource: How to include binary resource?
Post by: Keneto on July 13, 2006, 02:17:35 am
Working on a SpellCheck / Thesaurus component for Lazarus (It's actually 98% complete... I'll post it once I figure out how  :shock: )

Currently the Dictionary resides in a 5-meg file which you have to link to with a property and then include with your .exe... is there a way to get Laz to swallow this file into the .exe (and then link to it programmatically)? This will make deployment easier for new ppl, since they won't have that extra file to go find.

I'm thinking a huge binary resource... it's not entirely clear how I'd go about creating it. If anyone can point me along the way it'd be helpful.
Title: RE: Resource: How to include binary resource?
Post by: felipemdc on July 13, 2006, 02:36:08 am
On Windows you can create a .rc resource file, compile it with "windres" software that comes with lazarus. That will produce a .res file, which you can link into the executable putting this:

{$IFDEF Win32}
  {$R myresource.res}
{$ENDIF}

In the main program file (or other unit).

A RC file has statements like this:

101               ICON                    "iconfile.ico"

You can use windres like this, on the command line: windres -i magnifier.rc -o magnifier.res

There are some Windows API functions you can use to load the resource from the executable into memory.

If you want, you can use the Virtual Magnifying Glass as an example. Download the source code here: http://sourceforge.net/project/showfiles.php?group_id=60638

The source code contains a rc file, a batch script to compile that file, and source code that loads the contents of the resources into memory and uses them. It also contains IFDEFs to load the resources from files on Unixes, because on Linux you usualy donĀ“t link anything into the executable, you keep things on external files.
Title: RE: Resource: How to include binary resource?
Post by: Vincent Snijders on July 13, 2006, 07:38:58 pm
See also the FAQ on the wiki (http://wiki.lazarus.freepascal.org/index.php/Lazarus_Faq#How_to_embed_a_small_file_in_the_executable.2C_without_the_need_of_a_separate_file.3F_How_to_embed_a_resource.3F).

I don't know how well it works with large files. It will be hard on the compiler, but I think quiet efficient in the program.
Title: RE: Resource: How to include binary resource?
Post by: RudieD on July 13, 2006, 08:33:28 pm
I think a external one will still be the best, then you should be able to keep a central spelling "database?".
If you want to update the one, you don't NEED to update the other. If you want to add a language, you just add a "database?".
TinyPortal © 2005-2018