user3615169
user3615169

Reputation: 31

How to write and show something on Delphi IDE status bar

I want to know how can I write a module to show something like clock or other thing on Borland Delphi 7 IDE status bar, because I know it's possible but I couldn't find how!

Upvotes: 1

Views: 13753

Answers (2)

Free Consulting
Free Consulting

Reputation: 4412

Since OP didn't replied with more details, I'm going to post a little demonstration how to reach a status bar of Delphi's edit window. I had no success with adding new distinct status panel w/o disturbing layout, so I'm just changing the text of INS/OVR indicator panel.

Disclaimer: I still do not have access to the machine with Delphi 7 installed, so I've done that in BDS ("Galileo") IDE. However, differences should be minor. I believe what main difference lies in the way how we locate edit window.

Key strings are: 'TEditWindow' for edit window class name and 'StatusBar' for TStatusBar control name owned by edit window. These strings are consistent across versions.

{ helper func, see below }
function FindForm(const ClassName: string): TForm;
var
  I: Integer;
begin
  Result := nil;
  for I := 0 to Screen.FormCount - 1 do
  begin
    if Screen.Forms[I].ClassName = ClassName then
    begin
      Result := Screen.Forms[I];
      Break;
    end;
  end;
end;

procedure Init;
var
  EditWindow: TForm;
  StatusBar: TStatusBar;
  StatusPanel: TStatusPanel;
begin
  EditWindow := FindForm('TEditWindow');
  Assert(Assigned(EditWindow), 'no edit window');
  StatusBar := EditWindow.FindComponent('StatusBar') as TStatusBar;
  (BorlandIDEServices as IOTAMessageServices).AddTitleMessage(Format('StatusBar.Panels.Count = %d', [StatusBar.Panels.Count]));
  //StatusPanel := StatusBar.Panels.Add;
  StatusPanel := StatusBar.Panels[2];
  StatusPanel.Text := 'HAI!';
end;

initialization
  Init;

finalization
  // nothing to clean up yet

Another note: As you see, I use Open Tools API to output debug messages only, to interact with IDE I do use Native VCL classes. Therefore, this code must be in package.


The code above is a relevant part of the unit which should be contained in package. Do not forget to add ToolsAPI to uses clause as well as other appropriate referenced units (up to you). Package should require rtl, vcl and designide (important!). Since I run the testcase directly from initialization section, installing the package is enough for testcase to run and produce some result.

Upvotes: 0

R.P Silveira
R.P Silveira

Reputation: 402

To insert a text in a StatusBar, you have to insert a panel first. Just select your statusbar, find the property "Panels" (or perform double click over the statusbar) and click in "Add new". After that, you can write what you want inside the panel in the property "Text" (you can insert one or more panels). To do it programmatically, you can do something like this:

procedure TForm1.Timer1Timer(Sender: TObject);
begin
  StatusBar1.Panels[0].Text := 'Today is: ' + FormatDateTime('dd/mm/yyyy hh:nn:ss', Now);
end;

Upvotes: 2

Related Questions