Mirror

StatusBar: any number of panels and use the same procedure to update (Views: 100)


Problem/Question/Abstract:

Some times the use of a StatusBar is a hassle, when using 2 or more panels... and probably you write your procedure to update the statusbar... but then you notice you have to add another panel, then you have to change all the occurrences...

Answer:

you can put this procedure in a separate unit ("goodys.pas" in this example)

procedure SetStatusBar(var StB: TStatusBar; Strs: array of string);
var
  X: Byte;
begin
  for X := Low(Strs) to High(Strs) do
    if not (Strs[X] = '') then
      StB.Panels[X].Text := Strs[X];
  Application.ProcessMessages
end;

Then include that unit in your formunit

implementation

uses goodys;

and whenever you need to update your status bar, make a call

SetStatusBar(MyStatusBar, ['panel', '', 'another panel'])

no matter how many panels the StatusBar has, you can use the same procedure:

SetStatusBar(MyStatusBar, ['update my first panel only'])

Notes:
- to empty a panel, make a call with an space:

SetStatusBar(MyStatus, ['panel 2 should be empty', ' '])

- and make sure you have at least one panel in your statusbar, and the simplepanel property is False

<< Back to main page