?
Solved

single program instance to run when clicking on associated files

Posted on 2006-04-30
7
Medium Priority
?
360 Views
Last Modified: 2010-05-18
I have written a Delphi program.
I have associated it with "my" own file .fbn
When I click a .fbn, wonderful, my program starts, detect it has a param (the file) and open it accordinlgy
But now, my program is running, and when I click a second .fbn, a second instance of my program starts
Can I forbid that and in fact, get the "open this other file" info in my running program so that it can take action with it ?
0
Comment
Question by:LeTay
7 Comments
 
LVL 13

Expert Comment

by:BlackTigerX
ID: 16572824
the first thing would be to prevent multiple instances:

uses
  Windows,Forms,
  Unit1 in 'Unit1.pas' {Form1};


var
  Mutex : THandle;
{$R *.RES}

begin
Mutex := CreateMutex(nil, True, 'YourApplicationUniqueName');
if (Mutex <> 0) and (GetLastError = 0) then
  begin
  Application.Initialize;
  Application.CreateForm(TForm1, Form1);
  Application.Run;
  if Mutex <> 0 then
    CloseHandle(Mutex);
  end;
end.
0
 
LVL 13

Expert Comment

by:BlackTigerX
ID: 16572834
then you need to define a message on your form, which when received opens the file, I assume you have some kind of MDI application
0
 
LVL 4

Expert Comment

by:JDSkinner
ID: 16572852
You could use the approach indicated on the link below
http://delphi.about.com/od/windowsshellapi/l/aa100703c.htm

or you could just use a component from the ABF Software, if the program is for non commercial use
it is provided free of charge.
http://www.abf-dev.com/abf-components.shtml

The component to use is abfOneIstance, drop a copy of this on your form to catch a subsequent program copy.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 13

Accepted Solution

by:
BlackTigerX earned 1000 total points
ID: 16572853
here's an example on how to do that

http://delphi.about.com/od/windowsshellapi/l/aa100703b.htm

and here's an example of sending strings in a message, which is what you need to specify which file would need to be open

http://delphi.about.com/od/windowsshellapi/a/wm_copydata.htm
0
 
LVL 34

Expert Comment

by:Slick812
ID: 16574361
maybe the code in this EE Question may help you?

http://www.experts-exchange.com/Programming/Programming_Languages/Delphi/Q_20623659.html

ask questions if you need more information
0
 

Author Comment

by:LeTay
ID: 16585932
Hello BlackTigerX !
Your references look interesting
I have first tried the first one you suggest, writing a simple program
Unfortunately, the first instance of the program does not receive the message sent by the second one...
I can post it to you if you want to have a look at it
Then I tried the other approach, which looks better and which is to send a message directly to the "good" application (so the first instance)
I get a compilation error on this : procedure WMCopyData(var Msg:TWMCopyData); message WM_COPYDATA;
The error is : unknown directive 'message'.
No idea how to correct this.
I am running Delphi 5.
Thanks to help
0
 

Author Comment

by:LeTay
ID: 16586368
Sorry about this, I think I found the trick for compilation
I didn't declare the procedure as a private method of the form
Now it works
I still need to check and then, maybe, give you the points !
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

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…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses
Course of the Month17 days, 13 hours left to enroll

831 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