I understand you don't want to mess up some old dirty code by
adding your new feature.

How about this approach:
  At start-up (FormCreate) all menu-events are searched for
  using normal TForm.ComponentCount and TForm.Components) and
  if an OnClick-event is assigned, reassign it to a catch-procedure
  that will check if the user has the right access-level.
  If he has, just call the original procedure as if nothing has
  changed, otherwise you throw a warning-message.

I made a little demo for you that will demonstrate what I mean.
You can find it on my server and the idea is easilly adaptable to
any (large, dirty, ...) project and only takes a couple of lines.

=====>  http://delphi.videoripper.org/MenuCatch.zip

Of course this proof of concept has been written quickly and wasn't put
under stress, so you might want to extend the idea with valuable features.


Greetz,

Peter.


-----Oorspronkelijk bericht-----
Van: [email protected] [mailto:[EMAIL PROTECTED] Doug
Hale
Verzonden: maandag 15 september 2008 22:52
Aan: [email protected]
Onderwerp: Re: [delphi-en] How to intercept all menu events?


What has been suggested is that after login, you change the
enable/disable or Visible/Invisible state based on the role of whom
ever logged in.
Doug

[EMAIL PROTECTED] wrote:
> Oh, sorry.
>
> This is a retail application.
> Different user roles access the software simultaneously.
> Eg a supervisor may open the cash dawer for a clerk.
>
> Actions cannot be disabled, they may be used by an appropriate role.
> Or they may require this one-time authentication which I now seek to add.
>
> Menu items are password protected rather than disabled.
>
> This is a retrofit job. I am looking to intercept WM_COMMAND in
> Application.OnMessage and wondering how to map any part of that windows
> message back into an instance of TMenuItem.
>
>
>
>
>> Or, if you prefer, you could hide them: Visible:=False;
>>
>> Glenn Lawler
>> www.incodesystems.com
>>
>> -----Original Message-----
>> From: Smith David G (Finance) [SMTP:[EMAIL PROTECTED]
>> Sent: Monday, September 15, 2008 3:02 PM
>> To: [email protected]
>> Subject: RE: [delphi-en] How to intercept all menu events?
>>
>> Why not just disable the menu items the user is not permitted to use --
>> set the Enabled property to False?
>>
>> -----Original Message-----
>> From: [email protected] [mailto:[EMAIL PROTECTED] On
>> Behalf Of [EMAIL PROTECTED]
>> Sent: Monday, September 15, 2008 2:15 PM
>> To: [email protected]
>> Subject: [delphi-en] How to intercept all menu events?
>>
>>
>> Existing D5 application now needs security. Most of "security" involves
>> protecting access to menu items.
>>
>> I would like to implement this without bloating the code, adding lines
>> for every menu OnClick handler.
>>
>> There is already an Application.OnMessage handler in the code. I thought
>> I might add a handler for WM_COMMAND, intercepting menu clicks at that
>> point. Yet nothing in the TMsg structure seems to point me back to a
>> specific menu item.
>>
>> I see all menu items have automagically been assigned CMD ids, yet these
>> are not available in the data received by Application.OnMessage.
>>
>> What do I not understand, or is there a better way to intercept all menu
>> clicks for an existing application...?
>>
>> Thank you.

Reply via email to