Board index » delphi » Run One Program Only

Run One Program Only

I saw this posted here a few weeks back, can anyone repost it on how to
allow only one Delphi 3 compiled application(exe) to run.  I need this
as the users tend to click too many times on the icon and run multiple
instances of the exe which then bombs out since it is trying to share
DB's and Ports.... Thanks in advance.

--
http://www.geocities.com/Paris/3024/
Come and see the sights at the Renaissance Person's Webpage:
Historical Heroic stories, Napoleonic Uniforms, Game Info,
3D Art and Original Song Lyrics.

Remove the NO&SPAM to reply to this email.

 

Re:Run One Program Only


This seems to be the best way that I have found.

procedure TMainForm.FormCreate(Sender: TObject);
var hSem:THandle;
begin
  // Make sure we're the only one...
  hSem := CreateSemaphore(nil, 0, 1, 'MyApp');   // put your application
name here   ...it uses the Windows unit
  if ((hSem <> 0) AND (GetLastError() = ERROR_ALREADY_EXISTS)) then
    begin
      CloseHandle(hSem);
      MessageBeep(MB_ICONINFORMATION);
      MessageDlg('MyApp is already running.',mtInformation,[mbOK],0);
      Application.Terminate;
      System.Exit;
    end;

HTH,
Shane

  blah blah

Quote
davout <davout@NO&SPAMgeocities.com> wrote in message

news:BaQd4.2530$9F3.175158@news.corecomm.net...
Quote
> I saw this posted here a few weeks back, can anyone repost it on how to
> allow only one Delphi 3 compiled application(exe) to run.  I need this
> as the users tend to click too many times on the icon and run multiple
> instances of the exe which then bombs out since it is trying to share
> DB's and Ports.... Thanks in advance.

> --
> http://www.geocities.com/Paris/3024/
> Come and see the sights at the Renaissance Person's Webpage:
> Historical Heroic stories, Napoleonic Uniforms, Game Info,
> 3D Art and Original Song Lyrics.

> Remove the NO&SPAM to reply to this email.

Re:Run One Program Only


Quote
davout wrote:

> I saw this posted here a few weeks back, can anyone repost it on how to
> allow only one Delphi 3 compiled application(exe) to run.  I need this
> as the users tend to click too many times on the icon and run multiple
> instances of the exe which then bombs out since it is trying to share
> DB's and Ports.... Thanks in advance.

Think about using global named objects ... I suggest a mutex would be
very useful in this situation.

MH.

--
Martin Harvey. mar...@pergolesi.demon.co.uk
     http://www.pergolesi.demon.co.uk

The Usenet Oracle has pondered your question deeply.  Your question
was: Will your answer to this question be in the negative?
And in response, thus spake the Oracle: Memory fault.  Core dumped.

Re:Run One Program Only


Quote
davout wrote:
> I saw this posted here a few weeks back, can anyone repost it on how to
> allow only one Delphi 3 compiled application(exe) to run.  I need this
> as the users tend to click too many times on the icon and run multiple
> instances of the exe which then bombs out since it is trying to share
> DB's and Ports.... Thanks in advance.

The easiest thing to do is go to the DSP http://sunsite.icm.edu.pl/delphi/
and DL one of the many freeware components to do that. Most come with
source if you want to know how it's done.
-Chris

Other Threads