[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

How to populate a popup menu items with a query

Posted on 2002-05-07
7
Medium Priority
?
453 Views
Last Modified: 2010-08-05
I want to populate a popup menu with the result of a query. The popup menu should dynamically create items as per the result of query (query1.Recordcount) and then display the result.

thnks
0
Comment
Question by:drnadeem
[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
7 Comments
 
LVL 27

Expert Comment

by:kretzschmar
ID: 6993598
? trying from head (typos very possible)

var
  m : tmenuitem;
begin
  popupmenu1.items.clear;
  query1.first;
  while not query1.eof do
  begin
    m := tmenuitem.create(popupmenu1);
    m.caption := query1.fieldbyname('whatevername').AsString;
    m.onclick := AOnClickProcedureDefinedElseWhere;
    popupmenu1.items.add(m);
    query1.next;
  end;
end;
   

guessing i've mixed a bit with tlistitem, ttreenode,...
but somewhat in this way

meikl ;-)
0
 
LVL 9

Expert Comment

by:ginsonic
ID: 6993747
listening
0
 
LVL 3

Expert Comment

by:smurff
ID: 6993830
listening
0
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.

 
LVL 27

Expert Comment

by:kretzschmar
ID: 6993837
so much listeners :-))

if not solved within the next 4 hours,
then i will give a working sample

meikl ;-)
0
 
LVL 27

Accepted Solution

by:
kretzschmar earned 400 total points
ID: 6994525
well,

a working sample

the popup is used to filter a table
(i used the table orders from the dbdemos-alias)
by the field shipvia

the popup-content based on a query

unit add_menu_items_u;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, Grids, DBGrids, Menus, DBTables, Db;

type
  TForm1 = class(TForm)
    PopupMenu1: TPopupMenu;  //assigned to dbgrid, autohotkeys=maManual
    Table1: TTable;  //connected to dbdemos table orders
    DataSource1: TDataSource;
    Query1: TQuery;
    aa: TMenuItem;
    DBGrid1: TDBGrid;
    Button1: TButton;
    procedure PopupClick(Sender: TObject);
    procedure Button1Click(Sender: TObject);  //Popup-onClick
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

//popup-click action
procedure TForm1.PopupClick(Sender: TObject);
var
  t : tdatetime;
  s : string;
begin
  if (sender is tmenuitem) then
  begin
    s :=copy(tmenuitem(sender).caption,1,pos(':',tmenuitem(sender).caption)-1);
    caption := 'Records shown : '+s;
    if s = '*' then
      table1.filtered := false
    else
    begin
      table1.Filter := 'shipvia = '+quotedstr(copy(tmenuitem(sender).caption,1,pos(':',tmenuitem(sender).caption)-1));
      table1.filtered := true;
    end;
  end;
end;


//build popupmenu
procedure TForm1.Button1Click(Sender: TObject);
var
  m : tmenuitem;
begin
  query1.close;
  query1.sql.text := 'select shipvia, count(*) anz from orders group by shipvia';
  query1.open;
  popupmenu1.Items.Clear;
  query1.first;
  while not query1.eof do
  begin
    m := tmenuitem.Create(self);
    m.Caption := query1.fieldbyName('shipvia').AsString+':'+
                 intToStr(query1.fieldbyname('anz').AsInteger);
    m.OnClick := PopupClick;
    popupmenu1.Items.Add(m);
    query1.next;
  end;
  //an item to resolve the filter
  m := tmenuitem.Create(self);
  m.Caption := '*:All';
  m.OnClick := PopupClick;
  popupmenu1.Items.Add(m);
end;

end.

hope this helps

meikl ;-)
0
 
LVL 3

Expert Comment

by:VSF
ID: 6996194
You can also download a working sample on this matter at http://www.victory.hpg.com.br/Samples/Menusdinamicos.zip

Hope it helps!
VSF
www.victory.hpg.com.br
www.boatoda.hpg.com.br
0
 
LVL 6

Expert Comment

by:Holger101497
ID: 6997452
well - I think this is solved.
Just my 2c worth: I kinda miss the word ".Free" here?!

I think  "popupmenu1.Items.Clear;" just removes the items from the menu but doesn't destroy them. Sooner or later you'll have thousands of TMenuItems "floating around" ;) (do they use any system resources other than memory??)

Have fun,
             Holger
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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…
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…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

650 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