Solved

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

Posted on 2006-11-22
3
168 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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

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…
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…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

762 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

21 Experts available now in Live!

Get 1:1 Help Now