Solved

Additional TCustomMemo popup menu items

Posted on 2008-10-16
8
799 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
  • 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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

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…
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…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

839 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