delphi3000.com - the free delphi knowledge platform
delphi3000.com - the free delphi knowledge platform
486 Users Online NOW
Have a look at your member-status

connecting people's knowledge


  - Recent ArticlesRSS feed for Recent Articles on delphi3000.com
  - List of All Articles
  - Top Viewed Articles
  - Articles (+Attachem.)
  - Articles Of Interest
  - Categories
  - Top Uploader
  - Search
  - Index

  - My Home
  - Submit an Article
  - My Articles
  - My Personal Data
  - My Bookmarks
  - Activities
  - Login/Logout

  - Sign Up
  - Why Sign Up
  - Newsletter

  - Press
  - Advertise

  - Contact
  - Feedback





Community
Borland
ClubeDelphi
Dr. Bob
UK-BUG
Delphi Meetings
Planeta Delphi



Loremo - the 1.5 liter car coming in 2009




Startblatt.de






Share this article with friendsShare this article with friends
Rate this articleRate this article - to keep the quality of delphi3000.com !
Comment this article or read through previous comments (0)


This works: Save and Restore CoolbarsComponent available for this articleFormat this article printer-friendly!Bookmark function is only available for registered users!
Product:
Delphi 5.x (or higher)
Category:
VCL-General
Skill Level:
Scoring:
Last Update:
02/01/2002
Search Keys:
delphi delphi3000 article borland vcl code-snippet Save Coolbar settings Restore Coolbar settings Save and estore rrogram settings
Times Scored:
1
Visits:
1814
Uploader: Frank Heyne
Company:
Reference: N/A
Component Download: http://www.delphi3000.com/article/3026/ID3026.zip
 
Question/Problem/Abstract:
How can we save and restore Coolbars?
Answer:



{
We need to define an array which holds all settings.
In our example we use a Coolbar with 4 Toolbars.
If you have more or less Toolbars, you need to adjust
LastIndex in the following line:
}

const
  LastIndex = 3;  // First index is 0!

  // All the necessary data for our CoolBar with some ToolBars:
  // Writing this data to the Registry as binary data is trivial
  // and therefore left as an excercise to the reader.
  // Writing configuration data to a file is deprecated
  // in current Windows versions, btw.
  CBData: record
    position, width, flags: array[0..LastIndex] of integer;
  end;

procedure TForm1.SaveCBStatus;
var
  BandInfo: TReBarBandInfo;
  n, i: integer;
  TB: TToolBar;
begin
  with CBData do
  try
    // Positions:
    for i := 0 to LastIndex do
    begin
      TB := Coolbar1.controls[i] as TToolBar;
      position[i] := 0;
      while (TB <> Coolbar1.bands[position[i]].control)
      and (position[i] < Coolbar1.bands.count-1) do
      inc(position[i]);
    end;

    // New row or hidden? (Flags)
    for n := 0 to LastIndex do
    begin
      FillChar(BandInfo, SizeOf(TReBarBandInfo), 0);
      BandInfo.cbSize := SizeOf(TReBarBandInfo);
      BandInfo.fMask := RBBIM_STYLE or RBBIM_ID;
      Coolbar1.Perform(RB_GETBANDINFO, n, Integer(@BandInfo));
      flags[n] := BandInfo.fStyle;
      // Width:
      width[n] := CoolBar1.Bands[n].width;
    end;
  except
    ShowMessage('Exception in SaveCBStatus');
  end;
end;

procedure TForm1.RestoreCBStatus;
var
  p: array[0..LastIndex] of TCoolband;
  co: array[0..LastIndex] of integer;   // current order
  n, i: integer;
  BandInfo: TReBarBandInfo;
  TB: TToolBar;
begin
  with CBData do
  try
    // remember current order:
    for i := 0 to LastIndex do
    begin
      TB := Coolbar1.controls[i] as TToolBar;
      co[i] := 0;
      while (TB <> Coolbar1.bands[co[i]].control)
      and (co[i] < Coolbar1.bands.count-1) do
      inc(co[i]);
    end;

    // replace with old order:
    with Coolbar1 do
    begin
      for n := 0 to LastIndex do
      p[n] := bands[co[n]];

      // add as new ToolBars:
      for n := 0 to LastIndex do
      bands.insert(0);

      for n := 0 to LastIndex do
      bands.items[position[n]].assign(p[n]);

      // remove original ToolBars:
      for n := LastIndex+1 to  LastIndex+LastIndex+1 do
      bands.delete(LastIndex+1);
    end;

    // restore width and style:
    for n := Coolbar1.Bands.Count - 1 downto 0 do
    begin
      FillChar(BandInfo, SizeOf(TReBarBandInfo), 0);
      BandInfo.cbSize := SizeOf(TReBarBandInfo);
      BandInfo.fMask := RBBIM_SIZE or RBBIM_CHILD or RBBIM_STYLE;
      Coolbar1.Perform(RB_GETBANDINFO, n, Integer(@BandInfo));
      BandInfo.cx := width[n];
      BandInfo.fStyle := flags[n];
      Coolbar1.Perform(RB_SETBANDInfo, n, Integer(@BandInfo));
    end;
  except
    ShowMessage('Exception in RestoreCBStatus');
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin // Save the settings into CBData
  SaveCBStatus;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin  // Restore the settings from CBData
  RestoreCBStatus;
end;






Please rate this article!
Skill level:
BeginnerExpert

Useful:
No!Very!

Overall rating:
PoorExcellent



Comments to this article
Write a new comment













 
Sign up to consume product discounts for Bronze memberships !

read more


  Visit our Sponsor

 

  Community Ad of
M. Maes
 
   














 







     
  Copyright © 2000 - 2007 delphi3000.com - All rights reserved. Terms of use. || Privacy
delphi3000.com is a service by bluestep.com IT-Services GmbH (Vienna)