Solved

Making a 'recently used file' list in the File-menu at runtime (part3)

Posted on 2006-11-22
3
169 Views
Last Modified: 2010-04-05
Dear Experts,

I have ask twice the question how to make a 'recently used file' list.
and I have received good solutions and examples. Still I have 1 problem left
that I can not resolve on my own.

On my site you see a floppy-disc picture (beneath the Under Construction bar)
here you can download my example.

url: http://members.home.nl/peterkiers/

I have made this example to show you what exactly my problem is. My English is
very bad so I try to explain:

When you execute my example, choose menu-item Open and a OpenDialog-window
appears, you see tree files called: Arial9, Comic10 and Tahome10.
when you doubleclick on one of the files the file will be loaded BUT in a seperate
window, and I don't want that. The file has to be loaded in the window that allready
was opened. When you go back to menu-item File, you see the file Arial9 in the
menu that has recently been opened, when you click on it, the file will be loaded
again, but even here in a seperate window, and it has to be loaded in the window
that was allready open.

Who can help me to solve this problem?

Greetings,

Peter Kiers

P.s: I forgot to say that I made a menu-item called Check Filename to check
which file is loaded.

0
Comment
Question by:peterkiers
  • 2
3 Comments
 
LVL 4

Accepted Solution

by:
Meldrachaun earned 500 total points
ID: 17998431
The problem is that you're using ShellExecute to load the file - this is creating another instance of the program.  If I understand your code correctly, make these changes:

change Startup to accept a filename
    procedure Startup(filename: string);

in formcreate, at the end, call Startup like this:

  if ParamCount > 0 then
    Startup(ParamStr(1))
  else
    Startup('');

Change the top of startup to look like this:

procedure TForm1.Startup(filename: string);
begin
  if filename <> '' then
  begin
    LoadOptions(filename);
    CurrentFile := filename;

leave the rest of startup the way it is

then, in the places where you use ShellExecute, make these changes:

procedure TForm1.Open1Click(Sender: TObject);
var
  sFileName: string;
  i: Integer;
begin
  OpenDialog1.InitialDir := ExtractFileDir(Application.exename) + '\Sessions\';
  OpenDialog1.DefaultExt := 'emu';
  if OpenDialog1.Execute then
  begin
    sFileName := OpenDialog1.FileName;
  //   CurrentFile := OpenDialog1.FileName;
  //  ShellExecute(Handle, 'open', PChar(sFilename), nil, nil, SW_SHOWNORMAL);  << remove
    i := FRecentFiles.IndexOf(sFileName);
    if i >= 0 then
      FRecentFiles.Delete(i);
    ReloadFileList(sFileName);
    Startup(sFilename);     << Add
  end;
end;

and

procedure TForm1.OpenRecentFile(Sender: TObject);
var
  sFileName: string;
  i: Integer;
begin
  sFileName := FRecentFiles[TMenuItem(Sender).Tag];
  i := FRecentFiles.IndexOf(sFileName);
  FRecentFiles.Delete(i);
  ReloadFileList(sFileName);
//  ShellExecute(Handle, 'open', PChar(sFilename), nil, nil, SW_SHOWNORMAL);    << remove
  Startup(sFilename);    << add
end;
0
 
LVL 1

Author Comment

by:peterkiers
ID: 17998763
Hi, sorry for a late reaction, I will try your example whright now.

Peter.
0
 
LVL 1

Author Comment

by:peterkiers
ID: 17998875
Thanks works fine.

500p. comming your way.

Greetings,

Peter Kiers
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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…
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…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

863 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now