Board index » delphi » Coolbar Band Positions

Coolbar Band Positions

Hi All,

{Regarding Delphi 3.02 and the Coolbar and bands etc...}

   I've seen this problem mentioned several times now, but I've never
noticed an answer so I figure I'll try again.

There surely is no point in creating a Toolbar in your application
with movable bands, unless the positions of these bands can be saved.

However, the controls (both coolbar and coolbands) appear to have no
exposed properties which indicate the position of the bands. Given the
data, saving it and then loading it would be no problem.

Surely someone knows a way of getting at this data?

{ps. Please reply to the group, and via e-mail!}
--
Simon Steele - Student
ICQ: 2871108

 

Re:Coolbar Band Positions


Here's a quick way to write and read the coolbar data to a binary file(or
any component, for that matter):

procedure WriteCoolBarToFile(CoolBar: TCoolBar; FileName: string);
var
  Stream: TFileStream;
  Writer: TWriter;
begin
  Stream := TFileStream.Create(FileName, fmCreate);
  try
    Writer := TWriter.Create(Stream, 1024);
    try
       Writer.WriteComponent(CoolBar);
       Writer.WriteListEnd;
    finally
       Writer.Free;
    end;
  finally
    Stream.Free;
  end;
end;

procedure ReadCoolBarFromFile(CoolBar: TCoolBar; FileName: string);
var
  Stream: TFileStream;
  Reader: TReader;
begin
  if not FileExists(FileName) then Exit;
  Stream := TFileStream.Create(FileName, fmOpenRead);
  try
    Reader := TReader.Create(Stream, 1024);
    try
      Reader.BeginReferences;
      Reader.ReadComponent(CoolBar);
      Reader.EndReferences;
   finally
       Reader.Free;
    end;
  finally
    Stream.Free;
  end;
end;

How to write/read from the registry is left as an exercise for the reader
8r).
HTH,
Mark Duncan
Delphi QA

Quote
Simon Steele wrote in message <35e6a646.11668...@alternate.demon.co.uk>...
>Hi All,

>{Regarding Delphi 3.02 and the Coolbar and bands etc...}

>   I've seen this problem mentioned several times now, but I've never
>noticed an answer so I figure I'll try again.

>There surely is no point in creating a Toolbar in your application
>with movable bands, unless the positions of these bands can be saved.

>However, the controls (both coolbar and coolbands) appear to have no
>exposed properties which indicate the position of the bands. Given the
>data, saving it and then loading it would be no problem.

>Surely someone knows a way of getting at this data?

>{ps. Please reply to the group, and via e-mail!}
>--
>Simon Steele - Student
>ICQ: 2871108

Re:Coolbar Band Positions


Hi Simon,
    I use an ini file to save Coolbar band positions and widths.  Here's
how:

//Declare variables such as these or whatever names you want to use
var
    CBMainBreak: Boolean;
    CBMainWidth: Integer;
    CBAddrBreak: Boolean;
    CBAddrWidth: Integer;
    CBLInksBreak: Boolean;
    CBLinksWidth: Integer;
    StartPath: String;

//Add the following to the CoolBar1 Change event

procedure TForm1.CoolBar1Change(Sender: TObject);
begin
  CBMainBreak := CoolBar1.Bands[0].Break;
  CBMainWidth := CoolBar1.Bands[0].Width;
  CBAddrBreak := CoolBar1.Bands[2].Break;
  CBAddrWidth := CoolBar1.Bands[2].Width;
  CBLinksBreak := CoolBar1.Bands[3].Break;
  CBLinksWidth := CoolBar1.Bands[3].Width;
end;

procedure TForm1.ReadIniFile(Sender: TObject);
var
  ProgIni: TIniFile;
  i: Integer;
  tmpstr: String;
begin
  ProgIni := TIniFile.Create(StartPath + 'CoolBar.ini');
  try
    CoolBar1.Bands[0].Break := ProgIni.ReadBool('ToolBar', 'CBMainBreak',
True);
    CoolBar1.Bands[0].Width := ProgIni.ReadInteger('ToolBar', 'CBMainWidth',
628);
    CoolBar1.Bands[2].Break := ProgIni.ReadBool('ToolBar', 'CBAddrBreak',
True);
    CoolBar1.Bands[2].Width := ProgIni.ReadInteger('ToolBar', 'CBAddrWidth',
628);
    CoolBar1.Bands[3].Break := ProgIni.ReadBool('ToolBar', 'CBLinksBreak',
False);
    CoolBar1.Bands[3].Width := ProgIni.ReadInteger('ToolBar',
'CBLinksWidth', 9);
  finally
    ProgIni.Free;
  end;
end;

procedure TForm1.SaveIniFile(Sender: TObject);
var
  ProgIni: TIniFile;
  i: Integer;
  tmpstr: String;
begin
  {write to ini file}
  ProgIni := TIniFile.Create(StartPath + 'CoolBar.ini');
  try
    ProgIni.WriteBool('ToolBar', 'CBMainBreak', CoolBar1.Bands[0].Break);
    ProgIni.WriteInteger('ToolBar', 'CBMainWidth', CoolBar1.Bands[0].Width);
    ProgIni.WriteBool('ToolBar', 'CBAddrBreak', CoolBar1.Bands[2].Break);
    ProgIni.WriteInteger('ToolBar', 'CBAddrWidth', CoolBar1.Bands[2].Width);
    ProgIni.WriteBool('ToolBar', 'CBLinksBreak', CoolBar1.Bands[3].Break);
    ProgIni.WriteInteger('ToolBar', 'CBLinksWidth',
CoolBar1.Bands[3].Width);
  finally
    ProgIni.free;
  end;
end;

//On your main form's create procedure, read the ini file:
procedure TForm1.FormCreate(Sender: TObject);
begin
  StartPath := ExtractFilePath(Application.ExeName);
  if FileExists(StartPath + 'CoolBar.ini') then
    ReadIniFile(Sender);
end;

//On your main form's close procedure, save the ini file:
procedure TForm.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  ChDir(StartPath);
  SaveIniFile(Sender);
end;

That should do it--just another way of doing things.

Cheers,

Herminio

Quote
Mark Duncan wrote in message <6s7108$rm...@forums.borland.com>...
>Here's a quick way to write and read the coolbar data to a binary file(or
>any component, for that matter):

>procedure WriteCoolBarToFile(CoolBar: TCoolBar; FileName: string);
>var
>  Stream: TFileStream;
>  Writer: TWriter;
>begin
>  Stream := TFileStream.Create(FileName, fmCreate);
>  try
>    Writer := TWriter.Create(Stream, 1024);
>    try
>       Writer.WriteComponent(CoolBar);
>       Writer.WriteListEnd;
>    finally
>       Writer.Free;
>    end;
>  finally
>    Stream.Free;
>  end;
>end;

>procedure ReadCoolBarFromFile(CoolBar: TCoolBar; FileName: string);
>var
>  Stream: TFileStream;
>  Reader: TReader;
>begin
>  if not FileExists(FileName) then Exit;
>  Stream := TFileStream.Create(FileName, fmOpenRead);
>  try
>    Reader := TReader.Create(Stream, 1024);
>    try
>      Reader.BeginReferences;
>      Reader.ReadComponent(CoolBar);
>      Reader.EndReferences;
>   finally
>       Reader.Free;
>    end;
>  finally
>    Stream.Free;
>  end;
>end;

>How to write/read from the registry is left as an exercise for the reader
>8r).
>HTH,
>Mark Duncan
>Delphi QA

>Simon Steele wrote in message <35e6a646.11668...@alternate.demon.co.uk>...
>>Hi All,

>>{Regarding Delphi 3.02 and the Coolbar and bands etc...}

>>   I've seen this problem mentioned several times now, but I've never
>>noticed an answer so I figure I'll try again.

>>There surely is no point in creating a Toolbar in your application
>>with movable bands, unless the positions of these bands can be saved.

>>However, the controls (both coolbar and coolbands) appear to have no
>>exposed properties which indicate the position of the bands. Given the
>>data, saving it and then loading it would be no problem.

>>Surely someone knows a way of getting at this data?

>>{ps. Please reply to the group, and via e-mail!}
>>--
>>Simon Steele - Student
>>ICQ: 2871108

Re:Coolbar Band Positions


Mark,

I have been looking for a solution to this problem as well.  Your reply seemed
to be a great solution as well as a great piece of code to use in other
situations.  However, when I added the procedure calls to my FormCreate and
FormDestroy methods, it works with one exception.  My coolbar occupies two
lines because they cannot fit on the first line.  When I run the program
again, my coolbar only shows up on one line, thus "hiding" the second line.
And there is nothing I can do to get to those coolbar bands.  Do you have a
solution to this one small problem?  I tried different properties but had no
luck.

- PR

Quote
Mark Duncan wrote:
> Here's a quick way to write and read the coolbar data to a binary file(or
> any component, for that matter):

> procedure WriteCoolBarToFile(CoolBar: TCoolBar; FileName: string);
> var
>   Stream: TFileStream;
>   Writer: TWriter;
> begin
>   Stream := TFileStream.Create(FileName, fmCreate);
>   try
>     Writer := TWriter.Create(Stream, 1024);
>     try
>        Writer.WriteComponent(CoolBar);
>        Writer.WriteListEnd;
>     finally
>        Writer.Free;
>     end;
>   finally
>     Stream.Free;
>   end;
> end;

> procedure ReadCoolBarFromFile(CoolBar: TCoolBar; FileName: string);
> var
>   Stream: TFileStream;
>   Reader: TReader;
> begin
>   if not FileExists(FileName) then Exit;
>   Stream := TFileStream.Create(FileName, fmOpenRead);
>   try
>     Reader := TReader.Create(Stream, 1024);
>     try
>       Reader.BeginReferences;
>       Reader.ReadComponent(CoolBar);
>       Reader.EndReferences;
>    finally
>        Reader.Free;
>     end;
>   finally
>     Stream.Free;
>   end;
> end;

> How to write/read from the registry is left as an exercise for the reader
> 8r).
> HTH,
> Mark Duncan
> Delphi QA

> Simon Steele wrote in message <35e6a646.11668...@alternate.demon.co.uk>...
> >Hi All,

> >{Regarding Delphi 3.02 and the Coolbar and bands etc...}

> >   I've seen this problem mentioned several times now, but I've never
> >noticed an answer so I figure I'll try again.

> >There surely is no point in creating a Toolbar in your application
> >with movable bands, unless the positions of these bands can be saved.

> >However, the controls (both coolbar and coolbands) appear to have no
> >exposed properties which indicate the position of the bands. Given the
> >data, saving it and then loading it would be no problem.

> >Surely someone knows a way of getting at this data?

> >{ps. Please reply to the group, and via e-mail!}
> >--
> >Simon Steele - Student
> >ICQ: 2871108

Re:Coolbar Band Positions


Paul,

All I can think of off the top of my head would be to make sure that
CoolBar.Autosize = True, and that the first CoolBand's Break = True as well.
That's how my app is configured and it works just fine. The routine I posted
is a general streaming routine and isn't specific to the coolbar, so if
strange things are happening it's in how the CoolBar creates itself and/or
it's bands.

Thanks,
Mark Duncan,
Delphi QA

Quote
Paul Rapnikas wrote in message <35EADEBD.F7B03...@acgme.org>...
>Mark,

>I have been looking for a solution to this problem as well.  Your reply
seemed
>to be a great solution as well as a great piece of code to use in other
>situations.  However, when I added the procedure calls to my FormCreate and
>FormDestroy methods, it works with one exception.  My coolbar occupies two
>lines because they cannot fit on the first line.  When I run the program
>again, my coolbar only shows up on one line, thus "hiding" the second line.
>And there is nothing I can do to get to those coolbar bands.  Do you have a
>solution to this one small problem?  I tried different properties but had
no
>luck.

>- PR

Re:Coolbar Band Positions


on Mon, 31 Aug 1998 16:12:01 -0700, Mark Duncan may have written:

Quote
> All I can think of off the top of my head would be to make sure that
> CoolBar.Autosize = True, and that the first CoolBand's Break = True as well.
> That's how my app is configured and it works just fine. The routine I posted
> is a general streaming routine and isn't specific to the coolbar, so if
> strange things are happening it's in how the CoolBar creates itself and/or
> it's bands.

Having done this, the Coolbar reloads positions ok if both bands are
on the top line. However, once the coolbar has been reloaded, the
bands cannot be moved from the top line or they disappear. I've also
tried setting the Break property of both to True afterwards, but this
just causes one of the two bands I've created to disappear.
--
Simon Steele - Student
ICQ: 2871108

Other Threads