Solved

Start application once

Posted on 1998-09-12
3
155 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

Industry Leaders: 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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

713 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