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
Solved

base control that has a popupMenu

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

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

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…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

856 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