Solved

Additional TCustomMemo popup menu items

Posted on 2008-10-16
8
796 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:ciuly
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:ciuly
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
 

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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

705 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now