Extract a resource to file

Submitted by:Pitter Alderson

Date added:02 December, 2012

Category:Delphi

Delphi code example to extract a resource to file

Tags: extract

Code Snippet:

    procedure ExtractResource(ResourceName, FileName: string);
begin
ExtractResource(hInstance, ResourceName, Filename);
end;
procedure ExtractResource(hnd: Cardinal; ResourceName, FileName: string);
var
rStream: TResourceStream;
fStream: TFileStream;
begin
if FindResource(hnd, PChar(ResourceName), RT_RCDATA) <> 0 then
begin
rStream := TResourceStream.Create
(hnd, ResourceName, RT_RCDATA);
try
fStream := TFileStream.Create(FileName, fmCreate);
try
fStream.CopyFrom(rStream, 0);
finally
fStream.Free;
end;
finally
rStream.Free;
end;
end;
end;
 
 

Comments