Solved

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

Posted on 2006-11-22
3
173 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
[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
  • 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

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!

Question has a verified solution.

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

Suggested Solutions

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…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

756 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