Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 4 of 4 total
Thread Iterating through MenuBar items
Sun, May 30 2021 9:55 AMPermanent Link

StewCam

I have a form with a MenuBar. Currently I set the font of the active MenuBar item as bold on address anchor change using a block of type:

MenuBarItem1.Font.Style.Bold := True;
MenuBarItem2.Font.Style.Bold := False:
MenuBarItem3.Font.Style.Bold := False;

This works but gets cumbersome as the number of MenuBar items increases.

In order to reduce the number of repetitive false statements, I would like to iterate through the MenuBar items using a block of type:

for i := 0 to MenuBar.ItemCount - 1 do
begin
 MenuBar.Items[i].Font.Style.Bold := False;
end;

However,this syntax does not enable access to the font property, so I am looking for an alternative approach.
Sun, May 30 2021 8:06 PMPermanent Link

Alan Questell

Richmond Community College

Create a procedure ChangeFont in the form declaration

procedure ChangeFont(Sender: TComponent);

Procedure as follows:
procedure TForm1.ChangeFont(Sender: TComponent);
begin
  if Sender is TMenuBarItem then
     TMenuBarItem(Sender).Font.Style.Bold := true;
end;


Pass the items to that procedure:

begin
  for i := 0 to MenuBar1.ItemCount-1 do
     ChangeFont(MenuBar1.Items[i]);
end;



procedure TForm1.ChangeFont(Sender: TComponent);
begin
  if Sender is TMenuBarItem then
     TMenuBarItem(Sender).Font.Style.Bold := true;
end;




StewCam wrote:

I have a form with a MenuBar. Currently I set the font of the active MenuBar item as bold on address anchor change using a block of type:

MenuBarItem1.Font.Style.Bold := True;
MenuBarItem2.Font.Style.Bold := False:
MenuBarItem3.Font.Style.Bold := False;

This works but gets cumbersome as the number of MenuBar items increases.

In order to reduce the number of repetitive false statements, I would like to iterate through the MenuBar items using a block of type:

for i := 0 to MenuBar.ItemCount - 1 do
begin
 MenuBar.Items[i].Font.Style.Bold := False;
end;

However,this syntax does not enable access to the font property, so I am looking for an alternative approach.
Sun, May 30 2021 8:19 PMPermanent Link

Alan Questell

Richmond Community College

Sorry, part of that got copied twice.





Alan Questell wrote:

Create a procedure ChangeFont in the form declaration

procedure ChangeFont(Sender: TComponent);

Procedure as follows:
procedure TForm1.ChangeFont(Sender: TComponent);
begin
  if Sender is TMenuBarItem then
     TMenuBarItem(Sender).Font.Style.Bold := true;
end;


Pass the items to that procedure:

begin
  for i := 0 to MenuBar1.ItemCount-1 do
     ChangeFont(MenuBar1.Items[i]);
end;
Mon, May 31 2021 6:43 AMPermanent Link

StewCam

Thanks very much for your advice, which resolved my problem.


Alan Questell wrote:

Create a procedure ChangeFont in the form declaration

procedure ChangeFont(Sender: TComponent);

Procedure as follows:
procedure TForm1.ChangeFont(Sender: TComponent);
begin
  if Sender is TMenuBarItem then
     TMenuBarItem(Sender).Font.Style.Bold := true;
end;


Pass the items to that procedure:

begin
  for i := 0 to MenuBar1.ItemCount-1 do
     ChangeFont(MenuBar1.Items[i]);
end;
Image