Thema: Delphi TMenuItem.Tag

Einzelnen Beitrag anzeigen

stifflersmom
Online

Registriert seit: 8. Dez 2005
Ort: 24994 Holt
383 Beiträge
 
Delphi 10.2 Tokyo Professional
 
#7

AW: TMenuItem.Tag

  Alt 27. Mär 2025, 13:17
Ich denke, Du vertust Dich mit dem "richtigen" Zugriff auf die Menuitems

Hier ein Formular mit einem simplen Menu
Delphi-Quellcode:
object Form1: TForm1
  Left = 0
  Top = 0
  Caption = 'Form1'
  ClientHeight = 441
  ClientWidth = 624
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -12
  Font.Name = 'Segoe UI'
  Font.Style = []
  Menu = Mainmenu1
  TextHeight = 15
  object Button1: TButton
    Left = 48
    Top = 48
    Width = 241
    Height = 25
    Caption = 'EnabledDiableButton'
    TabOrder = 0
    OnClick = Button1Click
  end
  object Mainmenu1: TMainMenu
    Left = 304
    Top = 224
    object Enabled11: TMenuItem
      Caption = 'Enabled/Disabled'
      object Enables21: TMenuItem
        Caption = 'Enabled'
      end
      object Enabled1: TMenuItem
        Caption = 'Enabled'
      end
      object Disabled1: TMenuItem
        Tag = 1
        Caption = 'Disabled'
      end
    end
  end
end
Und hier der Code mit einem Button, der alle Menüenträge des ersten "Hauptmenüeintrages" durchiteriert und dann asublendet, wenn das Tag 1 asl Wert hat.
Delphi-Quellcode:
unit Unit1;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.Menus;

type
  TForm1 = class(TForm)
    Mainmenu1: TMainMenu;
    Enabled11: TMenuItem;
    Enables21: TMenuItem;
    Enabled1: TMenuItem;
    Disabled1: TMenuItem;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
    i : Integer;
begin

      for i := 0 to MainMenu1.items[0].Count -1 do
      begin
        MainMenu1.Items[0][i].Visible := (Mainmenu1.Items[0][i].Tag = 0);
      end;
end;

end.
  Mit Zitat antworten Zitat