?
Solved

base control that has a popupMenu

Posted on 2014-10-06
2
Medium Priority
?
196 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 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses
Course of the Month13 days, 17 hours left to enroll

801 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