2012-06-05 77 views
4

我創建了一個文件.Lrs和我導入到程序中,它的工作原理,但我如何從程序中獲取資源並將其提取到我的PC上的位置?這是代碼:提取拉撒路資源

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. 

謝謝!

回答

5

可以使用TLazarusResourceStream類,這是LResources單元

的一部分試試這個樣本

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; 
+0

謝謝,它的工作原理! –