Board index » delphi » Help experts! TNotebook component and page component access

Help experts! TNotebook component and page component access

Hi,

I have an application that uses a tnotebook component, and I'd like to step
through the buttons on the active page of the control.
I'm using Delphi 1, and I can see no apparent way of doing this.
I'll be most happy if someone knows of a way to do this, and can include a
small suggestion of the code.

Cheers,

Martin Platt.

 

Re:Help experts! TNotebook component and page component access


In article <77fasm$fn...@news1.cableinet.co.uk>, "Martin Platt"

Quote
<martin.platt.nos...@kewill-xetal.com> writes:
>I have an application that uses a tnotebook component, and I'd like to step
>through the buttons on the active page of the control.
>I'm using Delphi 1, and I can see no apparent way of doing this.
>I'll be most happy if someone knows of a way to do this, and can include a
>small suggestion of the code.

The pages of a TNoteBook are in the Controls array of the Notebook.
The controls on a page are in the Controls array of one of the pages.

You could access them like :-

var
  ActivePageId, i : integer;
begin
  ActivePageId := NoteBook1.Pages.IndexOf(Notebook1.ActivePage);
 {the NoteBook1.Controls[ActivePageId].Controls array
  contains all the controls on the active page}
  with NoteBook1.Controls[ActivePageID] do
    for i := 0 to ControlCount -1 do
      {some test to identify the button}
      with Controls[i] do
        if Name = 'Button2' then
          Enabled := false;
end;

 . . . or by name :-

  FindControl(Button2.Handle).Enabled := false;

Without knowing what you are really doing it's difficult to advise the best way
to approach the problem.

BTW I didn't know K-X were doing their stuff in Delphi - interesting <g>

Alan Lloyd
alangll...@aol.com

Re:Help experts! TNotebook component and page component access


Alan,

The code you supplied seems to step through the controls on the form for
some reason.

Here's the code I have.  What's I'm trying to do is make a popup menu
replect what is found on the buttons contained within a toolbar on the
active page of the TNotebook(nbToolbar) control.  Bit of a mouthful!

procedure TfrmOutstanding.CalculateMenuItems;
var
   nControl : Integer;
   NewItem : TMenuItem;
   iActivePage : Integer;
begin
     (* Remove menu items *)
     for nControl := 0 to (PopupMenu1.Items.Count-1) do
         PopupMenu1.Items.Delete(nControl);
     (* Step through buttons on toolbar, adding as items to popup menu *)
     iActivePage := nbToolbar.Pages.IndexOf(nbToolbar.ActivePage);
     with (nbToolbar.Controls[iActivePage]) do
     begin
         for nControl := 0 to (ControlCount-1) do
         begin
                  if (Controls[nControl] is TSpeedButton) then
                  begin
                       NewItem := TMenuItem.Create(Self);
                       NewItem.Caption :=
TSpeedButton(Controls[nControl]).Caption;
                       PopupMenu1.Items.Add(NewItem);
                       PopupMenu1.Items[PopupMenu1.Items.Count-1].Enabled :=
                         TSpeedButton(Controls[nControl]).Enabled;
                  end;
         end;
     end;
end;

P.S Who are you?!  Small world if you know K-X.....

Martin.

Re:Help experts! TNotebook component and page component access


Alan,

The problem is this.  This indexes of the strings in the Pages list do not
tally with the corresponding controls in the controls container.
I also had to perform some casting to a TPage class (found this out by
looking through the Delphi 4 component sources!)

So, it appears that I now have things going as I wanted.

Cheers for your help,

Martin.

Other Threads