Giacomo King Patermo
Giacomo King Patermo

Reputation: 849

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!

Upvotes: 4

Views: 1489

Answers (1)

RRUZ
RRUZ

Reputation: 136391

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; 

Upvotes: 5

Related Questions