Solved

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

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ddeman not working in activex 3 103
Delphi Yen format 3 31
Graphics32 under Delphi 10.1 Berlin 2 60
How to load 2 images in same column in Delphi 2 45
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…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

815 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

13 Experts available now in Live!

Get 1:1 Help Now