Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sender, Parent, Owner question... 2

Status
Not open for further replies.

LucieLastic

Programmer
May 9, 2001
1,694
GB
hi

I have a Pagecontrol and at runtime I do the following:-

1. Create and add new TTabSheets as required (newTab : TTabSheet).
2. For each TabSheet:-
newRich := TRichEdit.Create(self);
newRich.Parent := newTab;
newRich.align := alClient;
newRich.ScrollBars := ssBoth;
newRich.WordWrap := true;
newRich.PopupMenu := RichPopUp;

The problem :-
The popup has a menu item (Copy selected) but in the onclickCopy of the Popup, I don't know how to get the reference to the Richedit that 'called' it.

I thought this would work, but doesn;t, so obviously the sender isn't a TRichedit.
if Sender is TRichEdit then
(Sender as TRichEdit).CopyToClipboard;

How do I reference the 'triggering' Richedit so I can call its copy method ?

I think I need to reference the parent of the popup but not sure if assigning the popup to the richedit automatically becomes the parent.

big ta for any help
lou
[penguin]
 
Use the popup's PopupComponent property to determine which control triggered it.
 
Instead of saying
Code:
    newRich.PopupMenu := RichPopUp;
, you could set an event for newRich.OnMouseDown. That event would check to see if the mouse button held down is the right mouse button, and if it is, memorise the Sender in a global variable and call RichPopup.Popup.

Another alternative would be to create a new popup menu for each newRich. Then you could just set the popup's Owner as you create it.

Or you could check which tab of the PageControl is visible, and figure out from there which RichEdit we're talking about.
Code:
    for i := 0 to PageControl1.ActivePage.ComponentCount - 1 do
        if PageControl1.Components[i] is TRichEdit then
            // this must be the RichEdit that called us
-- Doug Burbidge mailto:doug@ultrazone.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top