Lazarus Resources

From Free Pascal wiki
Revision as of 22:09, 4 November 2005 by JayK (talk | contribs) (1st Version. Please read thru, revise, translate, correct and complete!)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

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.

Authors and Contributors

--JayK 21:09, 4 Nov 2005 (CET)