Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Start application once

Posted on 1998-09-12
3
Medium Priority
?
161 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 200 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

Independent Software Vendors: 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

Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

876 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