Skip to main content

How to Persist Settings Between Application Runs

  • 3 minutes to read

The ExpressPrinting System allows you to persist its settings to an INI file, registry, or stream. This topic describes how you can accomplish this automatically between application runs, and how to use a set of specially designed methods to do this manually at arbitrary points in an application.

Persisting Settings Automatically

Information that is automatically persisted by the ExpressPrinting System between application runs includes:

Settings other than those listed above should be persisted manually using ExpressPrinting System methods or the TcxPropertiesStore component.

To allow the ExpressPrinting System to automatically preserve its settings, specify the destination storage device and location for the information being stored:

  • An INI file. Assign dxstIniFile to the OptionsStoring.StorageType property of the currently active TdxPSEngineController component, and designate the filename via the OptionsStoring.IniFileName property. You can specify the full path to the file in order to store this file to a specific location, other than the application’s starting folder. You can also use a path relative to the application’s starting folder.

For print style managers, you should explicitly specify the AutoSave and StorageName properties to allow them to save their settings to separate files.

Once these properties are set, ExpressPrinting System settings are automatically saved when a dialog window, which corresponds to the settings, is destroyed, and are loaded when the dialog window is created.

Persisting Settings Manually

You can save settings of report links and certain printing components and dialog windows to an INI file or registry at any time, by calling a corresponding method:

To restore an object’s settings, call its LoadFromIniFile or LoadFromRegistry method.

You can also store settings of component printers and style managers to files or streams and restore them via the SaveToFile, SaveToStream, LoadFromFile, and LoadFromStream methods.

The following code sample demonstrates how to save settings of a component printer and its report links to a specific INI file and then restore from it.

var
  AFileName: string;
begin
  AFileName := 'comp_printer_settings.ini';
  dxComponentPrinter1.SaveToIniFile(AFileName);
  ...
  dxComponentPrinter1.LoadFromIniFile(AFileName);
end;

Note that these methods persist only a few report link properties, including format settings and the report’s start page. If this doesn’t meet your requirements, you can persist all report link settings via a stream’s WriteComponent and ReadComponent methods, as shown in the code sample below.

procedure SaveReportLink(AReportLink: TdxGridReportLink; AFileName: string);
var
  AStream: TFileStream;
begin
  AStream := TFileStream.Create(AFileName, fmCreate);
  try
    AStream.WriteComponent(AReportLink);
  finally
    AStream.Free;
  end;
end;
procedure LoadReportLink(AReportLink: TdxGridReportLink; AFileName: string);
var
  AStream: TFileStream;
begin
  AStream := TFileStream.Create(AFileName, fmOpenRead);
  try
    AReportLink.RestoreDefaults;
    AStream.ReadComponent(AReportLink);
  finally
    AStream.Free;
  end;
end;