Search code examples
windowsdelphiresourcesextractlazarus

extract lazarus resource


I created a file .Lrs and I imported into the program, it works, but how do I take the resource from the program and extract it to a location 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!


Solution

  • 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;