Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2006-11-22
3
Medium Priority
?
178 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 2000 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

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…
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…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

730 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