By coincidence, we needed to force only one instance of our app recently
so I re-read some of the posts on the issue.
One of the major problems that was probably overlooked by most solutions
(including the JustOne32 component), is what happens if your app
crashes.
For instance if your method creates something such as the global atom
below (or memory mapped files etc), then removes it on the FormDestroy
method, then what happens if you application dies with out hitting the
form destroy?
I have had a couple of commerical applications crash and it is annoying
to have to reboot to restart the app. Of course we being such fantastic
programmers our apps never crash so it not such a problem...<g>
Basically the best solution is search through the list of windows and
check if your window is still running. I should really wrap the code up
into a component & redistribute it someday but it is code developed in
work time...
Grant Black
Software Developer
SmartMove (NZ) Ltd
Phone: +64 9 361-0219 extn 719
Fax : +64 9 361-0211
Email: [EMAIL PROTECTED]
> -----Original Message-----
> From: Scott Cree [mailto:[EMAIL PROTECTED]]
> Sent: Monday, February 08, 1999 10:29 AM
> To: Multiple recipients of list delphi
> Subject: RE: [DUG]: JustOne32
>
>
> Someone was looking for some code to test if their application is
> already running a while ago. I just got this in the email from
> http://www.zdtips.com and it works alright, and looks pretty simple.
>
> Don't forget to declare Atom: TAtom in the private section.
>
> This week's Delphi Tip
>
> Make sure your .exe only runs once!
>
> The following code ensures that your .exe will only run once:
>
> procedure TForm1.FormCreate(Sender: TObject);
> begin
> {Searchs table to see if the program is already running}
> if GlobalFindAtom('PROGRAM_RUNNING') = 0 then
> { If not found then add it }
> atom := GlobalAddAtom('PROGRAM_RUNNING')
> else begin
> { If program is already running the show message and halt }
> MessageDlg('You have the program running all ready!!', mtWarning,
> [mbOK], 0);
> Halt;
> end;
> end;
>
> procedure TForm1.FormDestroy(Sender: TObject);
> begin
> {Removes the item from the table so it can be run again}
> GlobalDeleteAtom(atom);
> end;
>
>
> --------------------------------------------------------------
> ----------
> ---
> New Zealand Delphi Users group - Delphi List -
> [EMAIL PROTECTED]
> Website: http://www.delphi.org.nz
> --------------------------------------------------------------
> -------------
> New Zealand Delphi Users group - Delphi List -
> [EMAIL PROTECTED]
> Website: http://www.delphi.org.nz
>
---------------------------------------------------------------------------
New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
Website: http://www.delphi.org.nz