[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

TPopupmenu (Very difficult 'i think)

Posted on 1998-12-02
9
Medium Priority
?
342 Views
Last Modified: 2011-04-14
Hi!!
I have 1. Ini File, and with this ini file i want to do this.. I like to add all of ini string into popupmenu item
,when i have do that i will push the right mouse button and the popup menu will appear with items of all string in ini file.. and now when i click any item of popupmenu item i will then execute a program such a notepad
Example of my ini file
[Programs]
Notepad=C:\Windows\notepad.exe
i like to execute the notepad from popupmenu
And How? Thanks...
0
Comment
Question by:emiltor
[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
9 Comments
 
LVL 10

Expert Comment

by:viktornet
ID: 1348991
to execute the program just do something like this...

ShellExecute(0, 'open', PChar(PMnu.Items.Strings[PMnu.ItemIndex]), nil, nil, SW_NORMAL);

To load the strings to a opo up menu simply create items of type TMenuItem and insert them in the pop up menu...

To show the popup menu you could do spomething like PopUpMenu.PopUp; and maybe you'd have to give some x, and y values as the coordinates... Hope this info helps//

Cheers,
Viktor
0
 
LVL 4

Expert Comment

by:erajoj
ID: 1348992
Are you satisfied with Viktors answer or do you need sample code?
Just a comment; instead of entering "Notepad=C:\Windows\notepad.exe" in the ini-file, enter something like "1=&Notepad,C:\Windows\notepad.exe". Then you will be able to use custom shortcut keys in the popup menus using the ampersand(&).

/// John
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1348993
Oh shoot... I didn't mean to answer this... **** Please reject my answer.. I did it in my break in school so I didn't really noticed I was answering the question... That's not an answer at all..that's just to get you started....

Cheers,
Viktor
0
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!

 

Author Comment

by:emiltor
ID: 1348994
i´m finish doing this..... add all of ini file to popupmenu item. And now lets say the 1. caption in popupmenu item is notepad, then i will get the url behind that caption so i can execute notepad. Is this do on onchange event in popupmenu( i´m stop with this)
Thanks......
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1348995
this is in OnClick() if i understand yuor q'n right.,...
0
 
LVL 3

Expert Comment

by:williams2
ID: 1348996
Maybe this would help you.

You can use the Item.Tag property to set a specific index in a list. Then you should assign the OnChange event on all items to some procedure TForm1.BlaBlaOnChange(Sender: TObject)
(Do it with item.OnChange:=BlaBlaOnChange;)

Then you will be able to read the tag again with:

TForm1.BlaBlaOnChange(Sender: TObject);
var
  Index: Integer;
Begin
  index:= TMenuItem(Sender).Tag;
  //Here you should index the item in the list, and then go to execute the thing
End;

Cheers
/Williams
0
 

Author Comment

by:emiltor
ID: 1348997
procedure TAGluggi.FormCreate(Sender: TObject);
Var i                  : Integer;
    Men3,MenPassword      : TMEnuItem;
    Section,Fname,Furl : String;
begin
Ini := TIniFile.Create('D:\Down2\emmi.ini');
i := 0;
While popupmenu1.Items.Count > 0 Do
popupmenu1.Items.Delete(0);
Repeat
      Section := 'URL'+IntToStr(i);
      FName := Ini.ReadString(Section,'NAME','');
      FUrl := Ini.ReadString(Section,'URL','');
If FName <> '' Then
   Begin
   ListBox1.Items.Add(FName);
   ListBox2.Items.Add(FUrl);
   End;
   Inc(i);
Until FName = '';
For i := 0 to listbox1.Items.Count - 1 do
Begin
Men3 := TMenuItem.Create(Self);MenPassword := TMenuItem.Create(Self);
Men3.Caption := listbox1.Items.Strings[i];
Popupmenu1.Items.add(Men3);
End;
MenPassword.Caption := '&Password';
PopupMenu1.Items.Add(MenPassword);
PopupMenu1.Items[0].Tag := 5;
End;

------------------------------------------------------------------------------------------------------------------------

procedure TAGluggi.PopupMenu1Change(Sender: TObject; Source: TMenuItem;
  Rebuild : Boolean);
var
    Index : Integer;
Begin
    Index:= TMenuItem(Sender).Tag;
    If Index = 5 Then
    AGluggi.Close;
    //Here you should index the item in the list, and then go to execute the thing


Here are text of my code

Let's say for example, i like to add to the form.caption any of my popupmenu item "click"
text there...Thanks
0
 

Author Comment

by:emiltor
ID: 1348998
procedure TAWindow.FormCreate(Sender: TObject);
Var i                  : Integer;
    Men3,MenPassword      : TMEnuItem;
    Section,Fname,Furl : String;
begin
Ini := TIniFile.Create('D:\Down2\emmi.ini');
i := 0;
While popupmenu1.Items.Count > 0 Do
popupmenu1.Items.Delete(0);
Repeat
      Section := 'URL'+IntToStr(i);
      FName := Ini.ReadString(Section,'NAME','');
      FUrl := Ini.ReadString(Section,'URL','');
If FName <> '' Then
   Begin
   ListBox1.Items.Add(FName);
   ListBox2.Items.Add(FUrl);
   End;
   Inc(i);
Until FName = '';
For i := 0 to listbox1.Items.Count - 1 do
Begin
Men3 := TMenuItem.Create(Self);MenPassword := TMenuItem.Create(Self);
Men3.Caption := listbox1.Items.Strings[i];
Popupmenu1.Items.add(Men3);
End;
MenPassword.Caption := '&Password';
PopupMenu1.Items.Add(MenPassword);
PopupMenu1.Items[0].Tag := 5;
End;

------------------------------------------------------------------------------------------------------------------------

procedure TAWindow.PopupMenu1Change(Sender: TObject; Source: TMenuItem;
  Rebuild : Boolean);
var
    Index : Integer;
Begin
    Index:= TMenuItem(Sender).Tag;
    If Index = 5 Then
    AWindow.Close;
    //Here you should index the item in the list, and then go to execute the thing
   // This is from william2


Here are text of my code

Let's say for example, i like to add to the form.caption any of my popupmenu item "click"
text there...Thanks
0
 

Accepted Solution

by:
JStan earned 200 total points
ID: 1348999
{This is what I use to write filenames to the registry. You could easily change this
code to write to an '.ini' file instead.
You may be able to delete some of this code. Some of it is necessary to my prog
because the user can add programs to the list.
Also, I hope all the necessary code is here. I extracted it from 3000 lines of
code and it is possible that I may have missed some.
The code reads filenames from the reg and adds a hotkey to the menu item ( ie: &1,&2 etc.)
Then the code removes the hotkey part of the menu caption before trying to run the program.}
Also, the menu item shows only the Filename minus the .exe It just looks better.
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////

procedure TForm18.FormCreate(Sender: TObject);
var
Buffer: Array[0..255] of Char;
C,I: Integer;
W,F,S: string;
N: TMenuItem;
begin
      
      GetWindowsDirectory(Buffer,255);
           W := StrPas(Buffer);
           Externals := TStringList.Create;
      Externals.Sorted := True;
      Externals.Duplicates := dupIgnore;
      E  := TRegIniFile.Create('SoftWare\Company\Program');
      E.WriteInteger('Externals','0',5);                        //Write files to the reg
      E.WriteString('Externals','1',W+'\Explorer.exe');      //This could also go in
      E.WriteString('Externals','2',W+'\Calc.exe');          //a close procedure
      E.WriteString('Externals','3',W+'\Charmap.exe');      
      E.WriteString('Externals','4',W+'\PBrush.exe');
      E.WriteString('Externals','5',W+'\Notepad.exe');
      E.Free;
      E  := TRegIniFile.Create('SoftWare\Company\Program');  //Read files from the reg
      C := E.ReadInteger('Externals', IntToStr(0),0);
       if C > 0 then
          begin
               for I := 1 To C do
                begin
                     F := E.ReadString('Externals', IntToStr(I), 'Error');
                     if FileExists(ExpandFileName(F)) then
                     Externals.Add(F);                       //Populate the stringlist
              end;
         end;
      if PopupMenu1.Items.Count > 0 then                    //I use the popup over and
     for I := PopupMenu1.Items.Count - 1 downto 0 do         //again so lets clear it
        PopupMenu1.Items[I].Free;                            //from the last use
     if Externals.Count > 0 then
        for I := 1  To Externals.Count do                    //Now lets populate the
            begin                                            //popup using the stringlist
                 N := TMenuItem.Create(Self);
                 S := ExtractFileName(Externals[I-1]);
                 Delete(S,Pos('.',S),4);                     //set up the OnClick event
                 N.Caption := '&' + I + '  ' + S;            //Add a hotkey
                 N.OnClick := RunButtonClick;
                 N.Tag := I;
                 PopupMenu1.Items.Add(N);                    //Add to the popup
            end;

      E.Free;
end;

procedure TForm18.RunButtonClick(Sender: TObject);
var
   Command: string;
   D,E: string;
   I: Integer;
begin
   D := TMenuItem(Sender).Caption;                      //Get the menu caption
   Delete(D,1,4);                                       //Delete the Hotkey  
   for I := 0 to Externals.Count - 1 do                 //
       begin                                            //
            E := ExtractFileName(Externals[I]);         //Compare
            Delete(E,Pos('.',E),4);                     //       with
       if AnsiCompareFileName(E,D) = 0 then             //            the
          begin                                         //               Externals
               D := Externals[I];                       //assign filename to 'D'
               Break;
          end;
       end;
   Command := D + #0;
   if Winexec(@Command[1], SW_SHOWNORMAL) < 32 then     //Try to Run the program
      MessageDlg('Failed to execute ' + D,              //Or error out
      mtError,[mbOK], 0);
end;


             
             
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
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…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

656 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