Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Additional TCustomMemo popup menu items

Posted on 2008-10-16
8
Medium Priority
?
806 Views
Last Modified: 2010-04-21
I am working with a straightforward customised TLogMemo class (inherited from TCustomMemo) which shows the set of standard windows menu item options in a right-click popup menu (Undo,Cut,Copy,Paste,Delete,Select All).

I would like to add more MenuItems to these existing options and catch the notify event in my main form (containing the TLogMemo component), however am not sure how to achieve this. Even when I add a newly created TMenuItem (TLogMemo.Popupmenu.Add) I get an access violation.  Any advice would be appreciated.
0
Comment
Question by:brenlex
[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
  • 4
  • 2
  • 2
8 Comments
 
LVL 28

Expert Comment

by:2266180
ID: 22729642
the way to do it is like this (provided that the popup menu is created by the logmemo in it's create procedure and not because of some other external action (like at right cick (which doesn't make sense, but it is possible):


TNewMemo=class(TOldMemo)
public
  constructor Create(AOwner:TComponent); override;
end;
 
implementation
 
constructor TNewMemo.create(AOwner:TComponent);
begin
  inherited;// first create the parent class with everything
  popupmenu.items.add(whatever);
end;

Open in new window

0
 

Author Comment

by:brenlex
ID: 22730108
That's pretty much how I have been trying to do it thus far.  I am working with an existing component used extensively across the company's forms, whereby the popupmenu is not created in TLogMemo... it is created within one of the parent (StdCtrls) classes.  I was hoping that I might be able to just add a new menuitem to the parent's popup object, but I guess (as I still suffer from the access violation ) that the popup object has not yet been created, and is probably created when the event behind the mouse right-click is processed.

I have to presume therefore that I need to use my own popup menu instead, and recreate the code behind the existing popup menuitems ... unless anyone has any additional ideas...?
0
 
LVL 28

Expert Comment

by:2266180
ID: 22733660
creating your own popupmenu won't help. because even so, when the original is created and assigned, your instance is being pushed away (which might lead to memory leak if you create the popupmenu without an owner).

so, you need to find out what part of the code is creating the popumenu AND what part and when is it assigning it to the memo.

there is an easier solution if you have access to the original code: you will have to modify the log memo and (re)introduce your own popupmenu property, that way when the poroperty is being set, you have control and you can add items to it ;) this is the easiest solution :)
for anything else, I need to know when and who is creating and assigning the popupmenu.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:brenlex
ID: 22784770
Currently the TLogMemo component already has a published property PopupMenu (redeclared from base class). The hierarchy of the component is derived from the base VCL source as follows TLogMemo < TCustomMemo < TCustomEdit < TWincontrol < TControl < TComponent (where the Popupmenu is declared, though I am unsure when it is actually created during runtime - certainly not on creation of TLogMemo).

I am not looking to create my own popupmenu (as in example http://www.experts-exchange.com/Programming/Languages/Pascal/Delphi/Q_23112011.html), but somehow utilise my own menuitem with the existing windows default menuitems -- is this possible?

0
 
LVL 1

Expert Comment

by:leei
ID: 22785607
The local menu that you see (by default) for both the TCustomMemo and TCustomEdit classes is part of the underlying Windows EDIT control that these VCL controls wrap (nothing to do with VCL). It may be possible to extend this menu working directly with low-level windows messages directed to the underlying EDIT control, but that would require much more work than just creating and assigning your own TPopupMenu.

  MyPopup := TPopupMenu.Create(nil);
  mi := TMenuItem.Create(MyPopup);
  mi.Caption := 'Cut';
  mi.OnClick := method_to_perform_cut;
  MyPopup.Items.Add(mi);
  mi := TMenuItem.Create(MyPopup);
  mi.Caption := 'Copy';
  mi.OnClick := method_to_perform_copy;
  MyPopup.Items.Add(mi);
  ...

The PopupMenu property of any VCL control is _not_ assigned by default, so attempting to use it without first assigning an instance of TPopupMenu will generate errors (as you've seen). It's relatively easy to emulate the actions of the default popup menu in code (cut, copy, paste, delete, etc.). If you need help with that let me know. After creating and assigning an instance of TPopupMenu you can then add or remove menu items pragmatically to customize your custom descendant as needed.

 
0
 
LVL 1

Accepted Solution

by:
leei earned 1500 total points
ID: 22785651
Spell checker got away from me - that last sentence should say: After creating and assigning an instance of TPopupMenu you can then add or remove menu items _ programmatically _ to customize your custom descendant as needed.
0
 

Author Comment

by:brenlex
ID: 22789189
Thanks leei -- I just needed confirmation that there was no other means of accessing the windows generated messages.  I have already created my own popup menu programatically and written my own methods to emulate the previously available standard windows menu items.
0
 

Author Closing Comment

by:brenlex
ID: 31506667
Thanks for confirmation.
0

Featured Post

Independent Software Vendors: 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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

719 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