Lazarus Resources

From Free Pascal wiki
Jump to navigationJump to search

Deutsch (de) English (en) español (es) français (fr) 한국어 (ko) русский (ru)

Every win32 developer should know about resource files. They contain data which should be compiled into the exe file. That data could consist of images, string tables, version info, ... even an XP manifest and forms.

So now you cannot use "normal" resource files (*.res) in Lazarus because they are win32 specific. If you want to use your resources anyway, you will have to recreate them with lazres. Lazres can be found in the tools directory of your Lazarus installation folder (maybe you will first have to compile it).

Then you can compile Lazarus resource files (*.lrs) via command line. The syntax for lazres is:

lazres <filename of resource file> <files to include (file1 file2 file3 ...)>

To use a lazarus resurce file in your projects include the file with the $I compiler directive in the initialization section of your unit.

You can acces the data in the resources with the LoadFromLazarusResource method of the variables which will hold the file contents afterwards. LoadFromLazarusResource requires one string parameter which indicades which object should be loaded from the resource file.

Example:

procedure exampleproc;
var
  icon: TIcon;
begin
  icon := TIcon.Create;
  icon.LoadFromLazarusResource('myicon');
end;

initialization
  {$I mylazarusresource.lrs}

This code includes the file mylazarusresource.lrs into the project. In the procedure exampleproc an icon object is created and loaded from the object "icon" out of the resource. The file which was compiled into the resource was probably named myicon.ico.

Every class that is derived from TGraphic contains the LoadFromLazarusResource procedure.

Lazarus Resource Form File

Lazarus generate .LRS file from .LFM Form files. But it does not generate it automatically if .LRS file is missing.

When a LRS form file is missing, FPC reports the following error: ERROR: unit1.pas(193,4) Fatal: Can't open include file "unit1.lrs"

To solve it you must use lazres: c:\lazarus\tools\lazres.exe unit1.lrs unit1.lfm

The easiest way to recreate a .lrs file to make a trivial change in the form design, revert it and save the form, no need to use lazres. Vincent 09:47, 6 January 2009 (CET)

Authors and Contributors

JayK 21:35, 4 Nov 2005 (CET)