2006. február 2., csütörtök

How to save the position of TCoolBar bands in the registry


Problem/Question/Abstract:

I use a TCoolBar with several TToolbars and some other controls. During runtime a user can automatically reorder and resize the bands on the TCoolbar, is there a easy way of saving the positions and sizes of the different bands and reloading them a next time?

Answer:

You have to save the ID, Break, Width and Index of the bands. Following is a snippet of code that I use to save the Coolbar in the registry.

{ ... }

var
  RegristryFile: TRegIniFile;

const
  Ident = 'ID';
  Brk = 'Break';
  Wdth = 'Width';
  Ndx = 'Index';

  { ... }

procedure SaveCoolBars;
var
  A: Integer;
  IdStr: string;
begin
  with CoolBar, Bands do
  begin
    for A := 0 to Count - 1 do
      with Bands[A] do
      begin
        IdStr := IntToStr(Id);
        with RegristryFile do
        begin
          EraseSection(IdStr);
          WriteBool(IdStr, Brk, Break);
          WriteInteger(IdStr, Wdth, Width);
          WriteInteger(IdStr, Ndx, Index);
        end;
      end;
  end;
end;

procedure LoadCoolBars;
var
  A: Integer;
  B: TCoolBand;
  IdStr: string;
begin
  with CoolBar, Bands do
  begin
    for A := 0 to Count - 1 do
    begin
      B := TCoolband(Bands.FindItemID(A));
      if B = nil then
        Continue;
      with B, RegristryFile do
      begin
        IdStr := IntToStr(Id);
        Break := ReadBool(IdStr, Brk, Break);
        Width := ReadInteger(IdStr, Wdth, Width);
        Index := ReadInteger(IdStr, Ndx, Index);
      end;
    end;
  end;
end;

Nincsenek megjegyzések:

Megjegyzés küldése