Solved

Additional TCustomMemo popup menu items

Posted on 2008-10-16
8
800 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
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!

 

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 500 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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…
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 a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

740 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