Solved

Start application once

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

910 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

16 Experts available now in Live!

Get 1:1 Help Now