Board index » delphi » How can I check for previous instance

How can I check for previous instance

How can I check if there is a previous instance of the
present application? I'm using Delphi 3 Client/Server.
Is there something like PrevInstance in VB?

Best regards!
Rumen

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp   Create Your Own Free Member Forum

 

Re:How can I check for previous instance


rgar...@hotmail.com skrev i artiklen <6p1hhb$f9...@nnrp1.dejanews.com>...

Quote
> How can I check if there is a previous instance of the
> present application? I'm using Delphi 3 Client/Server.
> Is there something like PrevInstance in VB?

Included in our "ZieglerCollection one", you will find, among 50+ other
components, a component for doing just that, so if you would like a
ready-mad component, try downloading "ZieglerCollection one".

You can find "ZieglerCollection one" on our homepage at
http://www.zieglersoft.dk or http://www.zieglersoft.com

--

Warmest Regards from Claus Ziegler,

ZieglerSoft                    Email: cl...@zieglersoft.dk
Rughaven 25,2                         WWW: http://www.zieglersoft.dk
DK-9000 Aalborg , Denmark                   Phone: (+45) 9811 3772

Re:How can I check for previous instance


  hPrevInst is only available in 16bit....   In Delphi 3, the best way is to
create a mutext (CreateMutex) and see if the mutex is present...

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

Quote
rgar...@hotmail.com wrote in message <6p1hhb$f9...@nnrp1.dejanews.com>...
>How can I check if there is a previous instance of the
>present application? I'm using Delphi 3 Client/Server.
>Is there something like PrevInstance in VB?

>Best regards!
>Rumen

>-----== Posted via Deja News, The Leader in Internet Discussion ==-----
>http://www.dejanews.com/rg_mkgrp.xp   Create Your Own Free Member Forum

Re:How can I check for previous instance


Hello Rumen,

Just create a unit like this:
---------------------------------------------------------------------------------------------------

unit PrevInst;
{*****************************************************************************}

{* PrevInst32... Testen der Applikationen im
Speicher                        *}
{*****************************************************************************}

{* by ADRIAN
MEYER                                                           *}
{*
adrian.me...@berner.ch
*}
{*****************************************************************************}

interface

uses
 Windows, SysUtils, Forms;

type
 tMutexAttributes= record              { Attribute des Mutexes }
  Length: longint;
  SecurityDescriptor: pointer;
  InheritHandle: boolean;
 end;

 function IsPrevInst: boolean;            { Previous Instance da? }

var
 AppMutex: longInt;                 { Applikations Mutex }

implementation

{*****************************************************************************}

{* Applikation im Speicher?                  11.05.1998 ame *}
{*****************************************************************************}

function IsPrevInst: boolean;
var
 AppFileName: string;                { Application Filename }
 MutexAttributes: tMutexAttributes;         { Mutex Attributte }
 Mutex: longInt;                   { Mutex }
begin
 AppFileName := UpperCase( ExtractFileName( Application.ExeName ));

                          { Attributte setzen }
 MutexAttributes.Length := SizeOf( tMutexAttributes );
 MutexAttributes.SecurityDescriptor := nil;
 MutexAttributes.InheritHandle := False;

 Mutex := OpenMutex( MUTEX_ALL_ACCESS, True, pchar( AppFileName ));

 if ( Mutex <> 0 ) then               { Mutex schon da? }
  Result := True                                  { Ja }
 else
 begin                       { Nein }
  AppMutex := CreateMutex( @MutexAttributes, True, pchar( AppFileName ));
  Result := False;
 end;
end;

end.

---------------------------------------------------------------------------------------------------

and then include these 5 lines into your projects source code:

begin
 if IsPrevInst then
 begin
  MessageDlg( 'program already loaded.', mtInformation, [MBOK], 0 );
  Exit;
 end;

  Application.Initialize;
  Application.CreateForm(TfrmMain, frmMain);
  Application.CreateForm(TForm1, Form1);
  Application.Run;
end.

ADRIAN MEYER
adrian.me...@berner.ch

Quote
rgar...@hotmail.com wrote:
> How can I check if there is a previous instance of the
> present application? I'm using Delphi 3 Client/Server.
> Is there something like PrevInstance in VB?

> Best regards!
> Rumen

> -----== Posted via Deja News, The Leader in Internet Discussion ==-----
> http://www.dejanews.com/rg_mkgrp.xp   Create Your Own Free Member Forum

  vcard.vcf
< 1K Download

Other Threads