Solved

Start application once

Posted on 1998-09-12
3
151 Views
Last Modified: 2010-04-06
How can I prevent my application from being started twice? In Delphi 1 I could use the variable HPrevInst.

It's an MDI-application with various captions.
0
Comment
Question by:detempel
3 Comments
 
LVL 3

Expert Comment

by:Matvey
ID: 1339559
Several components exist, like this one:

http://bes.trendline.co.il/torry/vcl/system/bjustone.zip
"A component that enables only one unique instance of an application at each time."

There are several more on

http://bes.trendline.co.il/torry/system.htm, system2.htm, system3.htm, system4.htm

--Matvey
0
 
LVL 10

Accepted Solution

by:
viktornet earned 50 total points
ID: 1339560
Here is some code ;-)
----------
interface
uses Windows;
ResourceString
        AppCantStart = 'App is already running. Can not start another copy.';
        AppTitle = 'Just an App';
implementation
const
        TEN_SECONDS = 10000;
var
        MutexHandle : integer;
initialization
   MutexHandle := CreateMutex(Nil, False, 'DME Local Server Mutex.');
   if WaitForSingleObject(MutexHandle, TEN_SECONDS) <> WAIT_OBJECT_0
then
   begin
      MutexHandle := -1;
      Messagebox(0, PChar(RSCantStart), PChar(RSTitle), MB_OK);
      Halt;
   end;

finalization
        if MutexHandle <> -1 then
        ReleaseMutex(MutexHandle);
end.
--------------
Regards,
Viktor Ivanov
0
 

Author Comment

by:detempel
ID: 1339561
Adjusted points to 50
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
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…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

706 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