Solved

base control that has a popupMenu

Posted on 2014-10-06
2
192 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

717 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