Lazarus IDE: importing images into the project

I have recently migrated from Delphi XE6 to Lazarus IDE, and since I am not used to the new platform I would like to know how I can import images, videos and other resources in the project and thus use them (without the need to use a specific operating system directory).

Taking advantage of the same situation, it would be feasible to create a zip file and store or simply create a package in the project itself containing these features (and how could it the creation of this package and the reference of the resources in the Pascal code).

Note: I intend to use the images in a TImage object and set in the picture property.

I appreciate it now.

Author: Corvo, 2014-12-02

1 answers

Here I leave a tutorial with the solution to my question (contains some adaptations I made to facilitate the process).

Tutorial

First the Lazarus IDE has a tool called lazres.exe , located in the folder tools of Lazarus (X:\directory_do_lazarus \tools \ lazres.exe) - replace the one in bold with the Lazarus installation drive and directory.

After locating it I will be briefly explaining the operation of LazRes.

Introduction to LazRes

Its operation is by command lines and allows the creation of extension files LRS (Lazarus Resources) - a kind of package creator allowing you to add all the resources you want (such as images, audios, videos, general files, etc.).

For the package creation must be passed two parameters for the LazRes.exe , the LRS package name and the resources:

lazres.exe <nome_do_pacote.lrs> <arquivo1 arquivo2 arquivo3...>

Step 1: Preparing to create packages with a batch file

This step can be skipped if you know how to handle the command prompt and also lazres.exe

Copy and paste the code below into Notepad. You must save it in the same lazres directory.exe ( X:\directory_do_lazarus\tools) with the name of LRSBat.bat

LRSBat.bat :

@echo off
cls
pushd %~dp0
set l=^call lazres.exe 
%l%
echo.
set /p f=Nome do Pacote ^(.lrs^):
set f=%f:.lrs=%
set f=%f%.lrs
@echo.
set a=
set p=
@echo.
echo Arraste um arquivo de cada vez e pressione ENTER para adicionar mais.
echo Quando finalizar digite /f/ e pressione ENTER para gerar o pacote final.
:addArquivos
set /p "a=Arquivo: "
if "%a%"=="/f/" (goto:criarLRS)
if exist %a% (set p=%p% %a% )

goto:addArquivos

:abort
exit

:criarLRS
echo ---------------------------------
%l% %f% %p%
echo.
echo ---------------------------------
ECHO Fim.
pause>nul
exit

Step 2: Creating your first package (using LRSBat.bat)

Run the lrsbat file.bat as administrator and follow the procedures that are on the screen. If successful, an LRS file will be created in the same directory with the chosen name.

Step 3: Implementing the LRS file (package) in the Lazarus Project

Copy and paste the LRS file into your project.

With The Project Open in Lazarus and the code editor of the chosen unit, you will be incrementing the following lines:

uses ..., LResources;

. . .

{ Ao final do projeto antes do end. incluir as linhas abaixo }
initialization
 {$I nomedopacote.lrs}

end.

This will allow the compilation of the package package name.lrs along with the project executable.

Step 4: using an LRS package file in Project

For example, for adding a package image file to a Lazarus image component, follow the steps below. Suppose that the image component is componenteDeImagem and nome_do_arquivo References the package image name (without the extension):

componenteDeImagem.Picture.LoadFromLazarusResource('nome_do_arquivo');

Regardless of the component to be worked on, if you want to use a package file in the project you should make use of the LoadFromLazarusResource method.

References

Http://wiki.lazarus.freepascal.org/Lazarus_Resources

 2
Author: Corvo, 2014-12-07 00:19:03