Board index » delphi » Looking for component to limit App to one instance

Looking for component to limit App to one instance

   Like spending money, eh?   :)
   Use CreateMutex and then look for that mutex.  If it's present, your
application is running, so kill the second instance (by not calling
Application.Run)...

--
Jason Wallace
SL Software
Dark...@SLSoftware.reno.nv.us
--
"We are MicroSoft.  You will be assimilated.  Resistance is Futile."
--

Mark G. Zeringue <m...@ix.netcom.com> wrote in article
<01bcbdfa$7ea8da00$ac42ddcf@s{*word*199}>...

Quote
> Can anyone point me to a component which limits a Delphi application to
> only one instance at a time under Windows 95 or NT?

 

Re:Looking for component to limit App to one instance


Can anyone point me to a component which limits a Delphi application to
only one instance at a time under Windows 95 or NT?

Thanks
Mark

m...@ix.netcom.com

Re:Looking for component to limit App to one instance


This is a multi-part message in MIME format.
--------------9099BDD19720056F75204A63
Content-Type: text/plain; charset=us-ascii
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Transfer-Encoding: 7bit

Quote
Mark G. Zeringue wrote:
> Can anyone point me to a component which limits a Delphi application to
> only one instance at a time under Windows 95 or NT?

  OneInstance on my homepage. Freeware, with src.

Regards,

Erik.

--
Development of applications and drivers for Windows 95 and NT.
Go visit http://www.POBoxes.com/Sperling for some free source!
Check out Delphi Bug Lists at http://www.POBoxes.com/DelphiBugList
PGP public key available at http://www.POBoxes.com/Sperling/pgpkey.txt

Erik Sperling Johansen, Sperl...@POBoxes.com (DeBug Team; checker, monitor)

--------------9099BDD19720056F75204A63
Content-Type: text/x-vcard; charset=us-ascii; name="vcard.vcf"
Content-Transfer-Encoding: 7bit
Content-Description: Card for Sperling Johansen, Erik
Content-Disposition: attachment; filename="vcard.vcf"

begin:          vcard
fn:             Sperling Johansen, Erik
n:              Sperling Johansen;Erik
org:            Info-Pro
email;internet: Sperl...@POBoxes.com
title:          Developer
x-mozilla-cpt:  ;0
x-mozilla-html: TRUE
end:            vcard

--------------9099BDD19720056F75204A63--

Re:Looking for component to limit App to one instance


Mark G. Zeringue <m...@ix.netcom.com> wrote in article
<01bcbdfa$7ea8da00$ac42ddcf@s{*word*199}>...

Quote
> Can anyone point me to a component which limits a Delphi application to
> only one instance at a time under Windows 95 or NT?

Mark,
Check the value of HPrevInst. The following code is from the project
source:

begin
   if HPrevInst = 0 then begin
      Application.CreateForm(TfrmLogin, frmLogin);
      Application.Title := 'Your application title';
      Application.Run;
   end else begin
      MessageDlg('This application is already running on this
workstation.',
            mtWarning, [mbOk], 0);
   end;
end.

HTH.

--
Conor
   co...@globalgateway.com; remove -nospam to reply...

Re:Looking for component to limit App to one instance


On 10 Sep 1997 17:31:16 GMT, "Jason Wallace"

Quote
<Dark...@SLSoftware.reno.nv.us> wrote:
>   Like spending money, eh?   :)
>   Use CreateMutex and then look for that mutex.  If it's present, your
>application is running, so kill the second instance (by not calling
>Application.Run)...

>> Can anyone point me to a component which limits a Delphi application to
>> only one instance at a time under Windows 95 or NT?

I had the same problem, but I didn't understnd what is CreateMutex.

I didn't find it in the Delphi Help (and in the WinAPI too).

Thanks  Giacomo

Re:Looking for component to limit App to one instance


On 11 Sep 1997 16:21:37 GMT, "Conor Boyd"

Quote
<conor-nos...@globalgateway.com> wrote:

>Mark G. Zeringue <m...@ix.netcom.com> wrote in article
><01bcbdfa$7ea8da00$ac42ddcf@s{*word*199}>...
>> Can anyone point me to a component which limits a Delphi application to
>> only one instance at a time under Windows 95 or NT?

>Mark,
>Check the value of HPrevInst. The following code is from the project
>source:

HPrevInst works only on 16 bit applications.
Under Win32 the value is always 0.

Giacomo

Re:Looking for component to limit App to one instance


Quote
muss...@ipmchx.chfi.polimi.it (Giacomo Mussati) wrote:
>On 10 Sep 1997 17:31:16 GMT, "Jason Wallace"
><Dark...@SLSoftware.reno.nv.us> wrote:
>>   Like spending money, eh?   :)
>>   Use CreateMutex and then look for that mutex.  If it's present, your
>>application is running, so kill the second instance (by not calling
>>Application.Run)...

>>> Can anyone point me to a component which limits a Delphi application to
>>> only one instance at a time under Windows 95 or NT?

>I had the same problem, but I didn't understnd what is CreateMutex.
>I didn't find it in the Delphi Help (and in the WinAPI too).
>Thanks  Giacomo

A Mutex is an OS maintained variable that guards a region of code that
only one application can be in at once. It is mainly used for
Multi-threaded applications. other constructs that are used for
similar purposes include Critical sections and Semaphores. You'l find
out how these work in just about any book on multi-threaded
programming.

Martin Harvey.

***********************************************
Martin Harvey
Pembroke College, Cambridge University.
Uni email: mc...@hermes.cam.ac.uk
Home email: mc...@harvey27.demon.co.uk
Uni web pages: http://www-stu.pem.cam.ac.uk/~mch24/
***********************************************

Re:Looking for component to limit App to one instance


Quote
Mark G. Zeringue wrote:

> Can anyone point me to a component which limits a Delphi application to
> only one instance at a time under Windows 95 or NT?

First of all, the best way is *not* to use a component for this.
Why ? because this means that whenever the component detects there
is another copy already running, the 2nd copy is already started
and showing on the task bar. Although the 2nd program is usually
quit directly, it still flashes very shortly on the task bar.
I find this irritating and to avoid this you must program and detect
it yourself, and have your code to be the very first thing executed.

I wrote some examples of how to limit to only one instance on my
homepage: http://www.xs4all.nl/~pzaal/delphi/tips/application.htm#4
--
Peter

Remove the ~ from my address to send e-mail. Sorry.

Re:Looking for component to limit App to one instance


Quote
> >> Can anyone point me to a component which limits a Delphi application
to
> >> only one instance at a time under Windows 95 or NT?

> >Check the value of HPrevInst. The following code is from the project
> >source:

> HPrevInst works only on 16 bit applications.
> Under Win32 the value is always 0.

Check out this site for help:
http://www.informant.com/undu/DN960901/00000015.htm

John N Cox      
jcent.com

Other Threads