Solved

One instance and Kill program

Posted on 2003-11-10
2
427 Views
Last Modified: 2010-04-05
1) How can i make the program only run one (one instance) at a time ?
2) How can i kill the program if the program can not close normally ?
I had try the release(). Although the form was closed, i still
can see there is the process in Process Manager.
0
Comment
Question by:expert173173
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 4

Accepted Solution

by:
BedouinDN earned 100 total points
ID: 9719616
For single instance you can use a mutex.
Place the following in the source of your project (DPR) before the Application.Initialize part :-)
//---------------------------------
var
MutexHandle: THandle;

begin
MutexHandle := CreateMutex(nil, TRUE, App Name Here);
        if MutexHandle <> 0 then
        begin
                if GetLastError = ERROR_ALREADY_EXISTS then
                begin
                CloseHandle(MutexHandle);
                Halt; // 'Halt' Is the actual one that prevents a second
                end;
        end;
//-------------------------------------------------------------------------------

As for closing the application - When you close the form named as the main form, the application should terminate.
Failing this, you can try calling the Application.Terminate method instead of calling close however this is a bit nasty.
0
 
LVL 2

Expert Comment

by:SaLz
ID: 9719884
if your wondering what you should put in the app name it is the Class as in what you have named your form
you could put PChar((form1)) if you get errors
MutexHandle := CreateMutex(nil, TRUE, PChar(form1));
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

Suggested Solutions

Title # Comments Views Activity
Multiple image collision 13 105
Controlled Assessment GCSE - desperate help needed 4 119
DBCtrlGrid, Delphi, Scroll 7 34
TAction.OnAfterExecute? 2 30
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

739 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