Skip to main content

Saving and Restoring Bar Layout Manually

  • 2 minutes to read

The bar layout can be automatically saved by a bar manager, or manually by a user. The layout can only be automatically saved/restored if the bar manager belongs to a TForm or TFrame class instance. Otherwise, the layout should be saved/loaded manually by a user. This topic describes the ways you can accomplish this task.

Please refer to the Saving and Restoring Bar Layout Automatically topic, for information on how to save/restore the bar layout automatically.

How to Save the Bar Layout to the System Registry

The bar layout can be saved to the system registry by calling the bar manager’s SaveToRegistry method. You can then restore these settings using the bar manager’s LoadFromRegistry method. The values passed as parameters to these methods are treated as the registry keys, relative to the HKEY_CURRENT_USER root key. For instance, specifying ‘Software\MyCompany\MyProject’ will result in saving the settings to the ‘HKEY_CURRENT_USER\Software\MyCompany\MyProject’ path.

The following sample code shows how the bar layout can be saved to the specified system registry path, and then restored.

var
  ARegKey: string;
begin
  ARegKey := 'Software\MyCompany\MyProject';
  dxBarManager1.SaveToRegistry(ARegKey);
...
  dxBarManager1.LoadFromRegistry(ARegKey);
end;

How to Save the Bar Layout to a Stream

To save a bar layout to a stream (an instance of the TStream class or its descendant), call a bar manager’s SaveToStream method. You can then restore this information using the bar manager’s LoadFromStream method.

The following code snippet shows how the bar layout can be saved to a memory stream, and then restored.

var
  AStream: TMemoryStream;
begin
  AStream := TMemoryStream.Create();
  try
    dxBarManager1.SaveToStream(AStream);
    ...
    AStream.Position := 0;
    dxBarManager1.LoadFromStream(AStream);
  finally
    AStream.Free;
  end;
end;

How to Save the Bar Layout to an INI File

To save a bar layout to an INI file, call a bar manager’s SaveToIniFile method. To restore these settings, call the bar manager’s LoadFromIniFile method. The filename is passed as the parameter to these methods.

The following code sample demonstrates how the bar layout can be saved to the specified file, and then restored from it.

var
  AFileName: string;
begin
  AFileName := 'barlayout.ini';
  dxBarManager1.SaveToIniFile(AFileName);
  ...
  dxBarManager1.LoadFromIniFile(AFileName);
end;
See Also