Board index » delphi » How can I prevent an application to run twice simultaneously

How can I prevent an application to run twice simultaneously

I want to prevent my application from being launched more than once.

How can I activate the application that is already running when I try to
run it from the program manager.

Thank you !

PS : I use dephi under windows 3.1 and windows 95

 

Re:How can I prevent an application to run twice simultaneously


Check out this list of technical articles on Borland's Web Site - one of
them talks about what you are trying to do -- you may find some others that
are interesting too.
http://www.borland.com/devsupport/delphi/ti_list/

 Jean-Christophe ANGLADE wrote in article <01bc8140$676518a0$6410bfc2@pc-ang
lade.sapal.ch>...

Quote

>I want to prevent my application from being launched more than once.

>How can I activate the application that is already running when I try to
>run it from the program manager.

>Thank you !

>PS : I use dephi under windows 3.1 and windows 95

Re:How can I prevent an application to run twice simultaneously


On 25 Jun 97 08:18:00 GMT, "Jean-Christophe ANGLADE"

Quote
<jc.angl...@sapal.ch> wrote:

>I want to prevent my application from being launched more than once.

>How can I activate the application that is already running when I try to
>run it from the program manager.

>Thank you !

>PS : I use dephi under windows 3.1 and windows 95

You can easily find a component to put on the first of your forms...
It detects the multi instance of the application... Then exits...

Just look at www.delphi32.com

Re:How can I prevent an application to run twice simultaneously


Jean-Christophe ANGLADE <jc.angl...@sapal.ch> wrote in article
<01bc8140$676518a0$6410b...@pc-anglade.sapal.ch>...

Quote

> I want to prevent my application from being launched more than once.

> How can I activate the application that is already running when I try to
> run it from the program manager.

> Thank you !

> PS : I use dephi under windows 3.1 and windows 95

There are several components and units that accomplish this task
for you, available on e.g. the Delphi super Page.

Wim

Re:How can I prevent an application to run twice simultaneously


On 25 Jun 97 08:18:00 GMT, "Jean-Christophe ANGLADE"

Quote
<jc.angl...@sapal.ch> wrote:

>I want to prevent my application from being launched more than once.

>How can I activate the application that is already running when I try to
>run it from the program manager.

>Thank you !

>PS : I use dephi under windows 3.1 and windows 95

Modifying the project main program (View|Project Source)
as follows will do the trick:

uses
    Forms, WinProcs, WinTypes,
    Unit1 in 'UNIT1.PAS' {Form1};

var
    hWindow: HWnd;
begin
    { Check whether this is the first application instance }
    if hPrevInst <> 0 then begin
        { If not, browse Windows window manager, }
        { looking for main window of prev instance }
        hWindow := GetTopWindow(0);
        while hWindow <> 0 do begin
            if GetWindowWord(hWindow,GWW_HINSTANCE) = hPrevInst then
                if GetParent(hWindow) = 0 then begin
                    SetFocus(hWindow);  { Activate window when found }
                    Exit;
                end;
            hWindow := GetNextWindow(hWindow,GW_HWNDNEXT);
        end;
        Exit;     { Terminate }
    end;

    { This code is only reached if this is the first instance }
    Application.CreateForm(TForm1, Form1);
    Application.Run;
end.

Re:How can I prevent an application to run twice simultaneously


Hi,

Take the component JustOne from Delphi Super Page 16 bit freeware
components

NONN Vilmos
n...@dator.it

-------------------==== Posted via Deja News ====-----------------------
      http://www.dejanews.com/     Search, Read, Post to Usenet

Re:How can I prevent an application to run twice simultaneously


In article <01bc81a9$7dbc9ba0$2a86f1c3@default> "Wim van Hoorn" <cade...@worldonline.nl> writes:

Quote
>> PS : I use dephi under windows 3.1 and windows 95

>There are several components and units that accomplish this task
>for you, available on e.g. the Delphi super Page.

One good way is to lock a file, or in Win95 a global semaphore.  If you cannot
succeed in the lock, then the file is already locked presumably by another
instance of your application, and you terminate.  

Other Threads