Welcome to the new DelphiDabbler Code Library Documentation.

This is a new site that's currently running on alpha code. There are going to be bugs. If you discover any, please report them on the site's issues page (GitHub account required). Thanks.

Warning: Many URLs are going to change. Refer to the README file to discover which library project's documentation has been completed.

Example #9: Saving a resource file

Once you have created or modified a resource file object there comes a time when you need to save it somewhere. To do this we simply use the SaveToFile or SaveToStream methods of TPJResourceFile.

The following code shows how to use SaveToFile:

var
  ResFile: TPJResourceFile;
begin
  // Assume ResFile references a valid object
  ...
  // Save the file to 'MyResource.res'
  ResFile.SaveToFile('MyResource.res');
end;

The next code snippet shows how accomplish the same thing using SaveToStream:

var
  ResFile: TPJResourceFile;
  Stream: TStream;
begin
  // Assume ResFile references a valid object
  ...
  Stream := TFileStream.Create('MyResource.res', fmCreate);
  try
    ResFile.SaveToStream(Stream);
  finally
    Stream.Free;
  end;
end;

In real life we would just use the code in the first fragment, but this suffices as an example of using SaveToStream.

Links: