Lazarus IDE: Importing images into the project

Asked

Viewed 597 times

3

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

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 resources (and how could be making the creation of this package and the reference of the resources in the Pascal code).

OBS: I intend to use the images in a Timage object and set in the Picture property.

Thanks in advance.

1 answer

2


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 lazarus (X:\directory\tools lazres.exe) - replace the bold with the Lazarus installation unit 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 features you want (such as images, audios, videos, general files, etc).

To the creation of the package must be past two parameters to the Lazres.exe, the package name LRS 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 ignored if you know how to handle the command prompt and also lazres.exe

Copy and paste the code below into the notepad. You must save it in the same lazres.exe directory (X:\directory\tools) named after 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 file Lrsbat.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 folder.

With the project open in Lazarus and in the code editor of unit chosen, 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 nomedopacote.lrs together with the project executable.

Step 4: Using an LRS Package File in the Project

For example, for adding a package image file to a Lazarus image component, follow the procedures below. Suppose the image component is componenteDeImagem and the nome_do_arquivo refers to 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 method Loadfromlazarusresource.

References

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.