?
Solved

avoid click event

Posted on 2003-02-20
10
Medium Priority
?
245 Views
Last Modified: 2010-04-04
Hi,
 I need to override a click event from happening..
When i click a menu item, it shld check for a flag
and then popup the submenus based on the flag..
For a key events, i can set the key to #0,
How to achieve this for click event?..I'm using Tdxbarsubmenuitem...

Thanks
Prema
0
Comment
Question by:premaa
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
10 Comments
 
LVL 1

Accepted Solution

by:
User137 earned 100 total points
ID: 7985987
Click-events have one parameter: TObject Sender.

If i understood your question, you call this Click procedure from elsewhere? If so, you can call for example:

MenuItemClick(nil);

and

MenuItemClick(Sender: TObject);
begin
  if Sender=nil then begin
    // What happens when called from outside

  end else begin
    // What happens when clicked normally

  end;
end;
0
 
LVL 2

Assisted Solution

by:j42
j42 earned 100 total points
ID: 7986620
Hi,

I'm not sure if I understood your question? You want to check the flag before the menu is expanded and then decide wich items are in the menu?

Example:

If flag is true
File
  Open
  Close

If flag is false
File
  Foo

In the OnClick event of the File menu item code is to be:

OpenItem.Visible := flag;
CloseItem.Visible := flag;
FooItem.Visible := not flag;



I hope this may help. Please apologize my cryptic notation!

Regards
J
0
 
LVL 2

Expert Comment

by:j42
ID: 7986645
// Some code

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Menus, StdCtrls;

type
  TForm1 = class(TForm)
    MainMenu1: TMainMenu;
    File1: TMenuItem;
    Open1: TMenuItem;
    Close1: TMenuItem;
    Foo1: TMenuItem;
    CheckBox1: TCheckBox;
    procedure File1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.File1Click(Sender: TObject);
begin
  Open1.Visible := CheckBox1.Checked;
  Close1.Visible := CheckBox1.Checked;
  Foo1.Visible := not CheckBox1.Checked;
end;

end.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 14

Expert Comment

by:DragonSlayer
ID: 7991265
handle the OnPopup event instead of OnClick
0
 

Author Comment

by:premaa
ID: 7991841
Hi
user137,
Will the pop up not happen then? i tried to
make the sender nil in the barmanager click evnt
that raised an AV and then poped up the menu..

j42,
 I don't want to hide / disable the menus..as
there are many..just want to know if it's possible
using standard events alone..

Dragon ,
 what shld i do with the onpopup??
i tried to set it to nil, didn't work
the help says, a method "Do click" is there
and it shld be overriden..
I've created a bar manager that has many menu
and submenu items at design time itself..
how to override this procedure declared as
dynamic??

Thanks to all
Prema


 
0
 
LVL 1

Expert Comment

by:User137
ID: 7993709
"make sender nil" ???

No, you can't treat Objects like that...

For this case you can set the parameter to be any TObject on your project. So That Sender can contain a big variety of Flags.

Call examples:
MenuItemClick(nil);
MenuItemClick(MenuItem1);

OnClickEvent example:
SubMenuItem1Click(Sender: TObject);
begin
 if Sender=nil then begin
   ShowMessage('Flag is empty');
 end else if sender=MenuItem1 then begin
   ShowMessage('OnClick-Event called by MenuItem1');
 end else begin
   ShowMessage('Flag is non zero');
 end;
end;
0
 
LVL 2

Expert Comment

by:j42
ID: 8002529
DragonSlayer,
> handle the OnPopup event instead of OnClick
Are you talking about a TPopupMenu?

premaa,
What is a 'Tdxbarsubmenuitem'?

Some additionl information to what User137 already explained (so I do not want to be graded for that):

- In Delphi the visual components are pointers. Usually Delphi takes care of them and they point to the memory they should. If you set one of them to Nil you are no longer able to use it and your application may crash.

- If every component has its own OnClick procedure (e.g. Button1Click(Sender: TObject), Button2Click(Sender: TObject) ...) you do not have to care about the Sender. Sometimes you want to handle all the events within one procedure AllButtonsClick(Sender: TObject). So you have to care about the button from which this procedure is called:

procedure AllButtonsClick(Sender: TObject);
begin
  if (Button1 = Sender) then
  begin
    // Do something related to Button1
  end

  else
  if (Button2 = Sender) then
  begin
    // Do something related to Button2
  end
end;

Of course you can call this procedure like any other procedure and pass any pointer (including Nil) as parameter. These calls are valid:
  AllButtonsClick(Button1);   // Button1 is a pointer!
  AllButtonsClick(Nil);
  AllButtonsClick($FFFFFFFF);
But not all of these calls make sense.

The only way I know to prevent a menu item from poping up is to keep it empty. So my new solution to your problem is:
- Create a top level menu structure like this
  File(empty), Edit(empty)
- For each create as many TPopup menus as needed (depends on your flag)
  PopupMenu1, 2 for File item ; PopupMenu3, 4 for Edit item;
- In the OnClick event of your top level menu item popup the proper TPopupMenu
In the example below I was to lazy to get the coordinates. I just defined consts. Maybe you can post another q: 'How to get the lower left corner of a TMenuItem?' ;-)

// ***** Begin code

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Menus, StdCtrls;

type
  TForm1 = class(TForm)
    MainMenu1: TMainMenu;
    File1: TMenuItem;
    Edit1: TMenuItem;

    PopupMenu1: TPopupMenu;
    Test11: TMenuItem;

    PopupMenu2: TPopupMenu;
    Test21: TMenuItem;

    PopupMenu3: TPopupMenu;
    Test31: TMenuItem;

    PopupMenu4: TPopupMenu;
    Test41: TMenuItem;

    CheckBox1: TCheckBox;
    procedure AllMenusClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.AllMenusClick(Sender: TObject);
const
  DELTA_X_FILE = 6;
  DELTA_X_EDIT = 36;
  DELTA_Y = 40;
begin
  if (Sender = File1) then
  begin
    if CheckBox1.Checked then
    begin
      PopupMenu1.Popup(Self.Left + DELTA_X_FILE, Self.Top + DELTA_Y);
    end
    else
    begin
      PopupMenu2.Popup(Self.Left + DELTA_X_FILE, Self.Top + DELTA_Y);
    end;
  end
  else

  if (Sender = Edit1) then
  begin
    if CheckBox1.Checked then
    begin
      PopupMenu3.Popup(Self.Left + DELTA_X_EDIT, Self.Top + DELTA_Y);
    end
    else
    begin
      PopupMenu4.Popup(Self.Left + DELTA_X_EDIT, Self.Top + DELTA_Y);
    end;
  end;
end;

end.

// ***** End code

Regards
J
0
 

Expert Comment

by:CleanupPing
ID: 9317169
premaa:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
 
LVL 10

Expert Comment

by:kacor
ID: 9928597
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area for this question:
       to split points between j42 and User137
Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Some days and here is the Christmas Time. I wish good luck and good health for you all and for your loved ones

kacor
EE Cleanup Volunteer
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

764 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