Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

ItemCount in a TMenuItem

Posted on 1998-06-17
6
Medium Priority
?
370 Views
Last Modified: 2010-04-04
A simple question...

I am using D1 and WFW 3.11.  Can someone please tell me what is wrong in the following procedure.  It won't accept ItemCount as a property of the TMenuItem, but in the help file the example shows it should.  I have created the MenuItem(s) at runtime and want to check/uncheck items when clicked by the user. (So that only the latest clicked item is checked).  If I use Count instead of ItemCount it is accepted but always gives a value of 0.

procedure TForm1.NewItemClick(Sender: TObject);
var FName: String; N: Integer; ThisItem: TMenuItem;
begin
     ThisItem := TMenuItem.Create(File1);
     FName := TMenuItem(Sender).Name;
     For N := 0 to ThisItem.ItemCount-1 do               ThisItem.Items[N].Checked := False;
     TMenuItem(Sender).Checked := True;
     ThisItem.Free;
end;
0
Comment
Question by:jdthedj
6 Comments
 
LVL 5

Expert Comment

by:ronit051397
ID: 1353340
As far as I know there is no propery called ItemCount
0
 
LVL 1

Expert Comment

by:Socrates050697
ID: 1353341
Try using TMenuitem.Items.Count

ie in your program



    procedure TForm1.NewItemClick(Sender: TObject);
    var FName: String; N: Integer; ThisItem: TMenuItem;
    begin
         ThisItem := TMenuItem.Create(File1);
         FName := TMenuItem(Sender).Name;
         For N := 0 to ThisItem.Items.Count-1 do               ThisItem.Items[N].Checked := False;
         TMenuItem(Sender).Checked := True;
         ThisItem.Free;
    end;


Socrates
0
 
LVL 3

Accepted Solution

by:
vladika earned 200 total points
ID: 1353342
type
  TForm1 = class(TForm)
    MainMenu1: TMainMenu;
    file1: TMenuItem;
    Button1: TButton;
    Edit1: TEdit;
    procedure Button1Click(Sender: TObject);
    function CreateMenuItem(MenuCaption: string): TMenuItem;
    procedure OnMenuClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

function TForm1.CreateMenuItem(MenuCaption: string): TMenuItem;
begin
  Result := TMenuItem.Create(Self);
  Result.Caption := MenuCaption;
  Result.RadioItem := True;        // !!!!!!!!!!!!!!! - only one item checked
  Result.OnClick := OnMenuClick;     // OnClick event handler
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  // add to menu File1 MenuItem with Caption = Edit1.Text
  File1.Add(CreateMenuItem(Edit1.Text));
end;

procedure TForm1.OnMenuClick(Sender: TObject);
begin
  TMenuItem(Sender).Checked := True;  // Set checked
end;

0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 3

Author Comment

by:jdthedj
ID: 1353343
Hi

Thanks for all the replies.  

Socrates - that doesn't work either.

Ronit - One has to wonder why the help file shows ItemCount in its example code

Vladika - D1 doesn't have RadioItem capability in a TMenuItem, so I'm still stuck.

Any further ideas??
0
 
LVL 3

Expert Comment

by:vladika
ID: 1353344
In Delphi 1

type
  TForm1 = class(TForm)
    MainMenu1: TMainMenu;
    file1: TMenuItem;
    Button1: TButton;
    Edit1: TEdit;
    procedure Button1Click(Sender: TObject);
    procedure OnMenuClick(Sender: TObject);
  private
    function CreateMenuItem(MenuCaption: string): TMenuItem;
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

function TForm1.CreateMenuItem(MenuCaption: string): TMenuItem;
begin
  Result := TMenuItem.Create(Self);
  Result.Caption := MenuCaption;   // Set Caption
  Result.OnClick := OnMenuClick;   // OnClick event handler
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  File1.Add(CreateMenuItem(Edit1.Text));
end;

procedure TForm1.OnMenuClick(Sender: TObject);
var I: Integer;
    ParentMenu: TMenuItem;
begin
  ParentMenu := TMenuItem(Sender).Parent;  // Parent Menu Item
  for I := 0 to ParentMenu.Count-1 do
    ParentMenu.Items[I].Checked := False;  // Uncheck all Items in ParentMenu
  TMenuItem(Sender).Checked := True;  // Check clicked MenuItem
end;

//

ItemCount is misprint -> Use Count



0
 
LVL 3

Author Comment

by:jdthedj
ID: 1353345
Thanks Vladika - I tried all sorts of things, but couldn't figure out how to refer to the MenuItems.  I'm very grateful for your help.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Suggested Courses

927 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question