?
Solved

Open button with Recent List

Posted on 2003-03-22
2
Medium Priority
?
230 Views
Last Modified: 2010-04-04
I would like to create an open button that when executed opens the opendialog option (this is easy lol), and when I open more files an arrow appears (this button with an arrow is similar to the one to select a font/color on Word etc.) that lists recent files that was opened, and also on this menu that have the recent files a button to clean the recent files list

thanks for any help on this
0
Comment
Question by:paulo67
2 Comments
 
LVL 3

Accepted Solution

by:
lmikle earned 360 total points
ID: 8185899
Use a TToolButton with tbsDropdown style.
Attach any popup menu to DropdownMenu property.
Also, add to this menu separator and 'Clear' menu item.

In following example popup menu has separator as 1st item and 'Clear' menu item as 2nd. Set Tag property on separator menu item to 1 (this will be used as stop flag).

Create procedure that will be called then recent menu item will be clicked:

procedure TForm1.RecentMIClick(Sender: TObject);
begin
  // Show file name that placed in item caption
  ShowMessage((Sender As TMenuItem).Caption);
end;



Then you open any file(s) add menu items in a head of this popup menu:

procedure TForm1.ToolButton1Click(Sender: TObject);
var
  I, J : Integer;
  MI : TMenuItem;
begin
  // OpenDialog1.Execute - call standard open handler

  // peocessing opened files
  For I := 0 To openDialog1.Files.Count-1 Do
    Begin
      // Check - does file already exists. If Yes - remove one
      For J := 0 To PopupMenu1.Items.Count-1 Do
        Begin
          If PopupMenu1.Items[J].Tag = 1 Then Break;
          If PopupMenu1.Items[J].Caption = OpenDialog1.Files[I] Then
            Begin
              Popupmenu1.Items.Delete(J);
              Break;
            End;
        End;

      // Add new menu item
      MI := TMenuItem.Create(Self);
      MI.Caption := OpenDialog1.Files[I];
      MI.OnClick := RecentMIClick;
      PopupMenu1.Items.Insert(0,MI);
    end;
end;

And at the finish create a clear handler - it will remove all items except separator and 'Clear' item. We use a separator Tag property as stop flag too:

procedure TForm1.Clear1Click(Sender: TObject);
begin
  While PopupMenu1.Items.Count > 0 Do
    Begin
      If PopupMenu1.Items[0].Tag = 1 Then Break;
      PopupMenu1.Items.Delete(0);
    End;
end;
0
 

Author Comment

by:paulo67
ID: 8271792
sorry i had some problems with my computer and couldn't login anymore
thanks for the help it works great
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

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 response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
How can you see what you are working on when you want to see it while you to save a copy? Add a "Save As" icon to the Quick Access Toolbar, or QAT. That way, when you save a copy of a query, form, report, or other object you are modifying, you…
Suggested Courses

599 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