Retrieve lazarus resource

I created a .Lrs file and I imported it into the program, it works, but how can I take a resource from the program and extract it to a folder on my PC? This is the code:

unit Unit1; {$mode objfpc}{$H+} interface uses Classes, SysUtils, FileUtil, Forms, LResources, Controls, Graphics, Dialogs, ExtCtrls; type { TForm1 } TForm1 = class(TForm) procedure FormCreate(Sender: TObject); private { private declarations } public { public declarations } end; var Form1: TForm1; implementation {$R *.lfm} { TForm1 } procedure TForm1.FormCreate(Sender: TObject); begin end; initialization {$I resource.lrs} end. 

Thanks!

+4
source share
1 answer

You can use the TLazarusResourceStream class, which is part of the LResources unit

Try this sample

 var Stream: TLazarusResourceStream; begin Stream := nil; try //load the lazarus resource Stream := TLazarusResourceStream.Create('image', nil); //save to a file Stream.SaveToFile('C:\Foo\image.png'); finally Stream.Free; end; end; 
+5
source

Source: https://habr.com/ru/post/1416262/


All Articles