Solved

base control that has a popupMenu

Posted on 2014-10-06
2
190 Views
Last Modified: 2014-10-09
A function in one of my Delphi 2010 libraries creates a TPopupMenu on the fly. I need to create a procedure that lets me pass a control to associate the menu with. For example, a TEdit has a PopupMenu property, as does a TMemo, a TcxDbTreeList, etc. I obviously don't want to write a separate overloaded procedure for every control type that I'll ever want to associate my menu with, but I can't figure out what base class that lets me set the Popupmenu property. For example, I can't write
if Sender is TWinControl then TWinControl(Sender).popupMenu := myMenu;

Open in new window

because TWinControl doesn't have the PopupMenu property. What class base supports the PopupMenu property?.  Thanks much.
0
Comment
Question by:EricTaylor
[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
2 Comments
 
LVL 27

Accepted Solution

by:
Sinisa Vuk earned 500 total points
ID: 40364928
I take example from: http://delphi.about.com/od/adptips2005/qt/setdatasource.htm
...and modified a little:
procedure ApplyPopupMenu(myCtrls: array of TControl; pm: TPopupMenu);
var
   cnt: Integer;
   PropInfo: PPropInfo;
begin
   for cnt := Low(myCtrls) to High(myCtrls) do
   begin
     PropInfo := GetPropInfo(myCtrls[cnt].ClassInfo, 'PopupMenu') ;
     if Assigned(PropInfo) then
       SetOrdProp(myCtrls[cnt], PropInfo, LongInt(pm)) ;
   end;
end;

procedure TForm1.Button12Click(Sender: TObject);
begin
  ApplyPopupMenu([VirtualStringTree1, DBGrid1, Memo1], PopupMenu1);
end;

Open in new window


This will set popupmenu for all components in call (if property PopupMenu exist) using Rtti functions.
0
 

Author Closing Comment

by:EricTaylor
ID: 40372025
Thanks, Sinisa. In this case, I only need to pass one TControl, but this was helpful in getting and setting the desired property. (Seems a little convoluted that those properties would be that awkward to get to, but that's another issue.)
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

730 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