Solved

base control that has a popupMenu

Posted on 2014-10-06
2
184 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
2 Comments
 
LVL 25

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
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…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

746 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

12 Experts available now in Live!

Get 1:1 Help Now