Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Simple Easy, Check For Instance Of Running Program

Posted on 2000-04-11
11
Medium Priority
?
306 Views
Last Modified: 2010-04-04
Hi Folks, sometime ago i had a bit of code that created an "atom" and when a program ran, it looked to see if it was already in memory if it was my delphi program would not run until it closed it down..... it was only a few lines long.....

I don't suppose anyone here has the code, or an alternative solution to this? :)

Thanks....

Craig C.
0
Comment
Question by:craig_capel
  • 4
  • 3
  • 3
  • +1
11 Comments
 
LVL 10

Expert Comment

by:Lischke
ID: 2703990
Hi Craig,

it is AddAtom, FindAtom and DeleteAtom in the Win32 API.

Ciao, Mike
0
 
LVL 6

Expert Comment

by:edey
ID: 2704183
Though Atoms are used for this purpose, it isn't generally recomended as the size of the atom table (and the atoms) is limited, one of those "provided for compatibility" things.  This is a pretty commonly asked question, though, so heres a previously asked question (should *always* try the search engine first :) on semaphores (found searching for "one instance"):

http://www1.experts-exchange.com/bin/ShowQ?qid=10121069&search=

GL
Mike
0
 
LVL 2

Accepted Solution

by:
CalvinDay earned 140 total points
ID: 2704463
I use something like this:

program xPrint;

uses
  Hide1,
  Hide2,
  Windows,
  Forms,
  uPrint in 'uPrint.pas' {fPrint},
  uAbout in 'uAbout.pas' {fAbout};

{$R *.RES}

begin
  CreateMutex(nil,false,'xPrint');
  if GetLastError=ERROR_ALREADY_EXISTS then
    begin
    SendMessage(HWND_BROADCAST,RegisterWindowMessage('xPrint'),0,0);
    Halt(0);
    end;

  Application.Initialize;
  Application.Title := 'xPrint';
  Application.CreateForm(TfPrint, fPrint);
  Application.Run;
end.


You can use the sendmessage to alert the other instance to wake up.

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Author Comment

by:craig_capel
ID: 2704581
edey, although true, how would you get easy points?.....

ok just testing out a couple of your suggestions... Thanks all, brb....
0
 
LVL 2

Author Comment

by:craig_capel
ID: 2708040
sorry for the delay.... recovering from a hangover.... :)

But your code worked great..... Thanks a lot, sorry for the lack of points....
0
 
LVL 10

Expert Comment

by:Lischke
ID: 2709208
Hi Craig,

please formulate your future questions a bit more carefully. I honestly thought you need to work with atoms not just to prevent your application from running twice. Otherwise I had given you an elegant solution. The broadcast thingy is really bad as it needs on some machine several seconds to return. For a precise question you can get really professional answers. Consider this...

Ciao, Mike
0
 
LVL 2

Expert Comment

by:CalvinDay
ID: 2709274
Mike,

I agree with your statement about the broadcast. Setting up and trapping the broadcast is really a pain.

If you have a more elegant (hopefully simple) soluton to this please let us know. I will post a 50 point question for it.

Please post it here.
0
 
LVL 2

Expert Comment

by:CalvinDay
ID: 2709332
Mike,

I agree with your statement about the broadcast. Setting up and trapping the broadcast is really a pain.

If you have a more elegant (hopefully simple) soluton to this please let us know. I will post a 50 point question for it.

Please post it here.
0
 
LVL 2

Expert Comment

by:CalvinDay
ID: 2709336
Don't ya hate that.
0
 
LVL 2

Author Comment

by:craig_capel
ID: 2709375
I don't suppose anyone here has the code, or an alternative solution to this? :)

Lischke... Sorry, but i don't want to sound rude, but i did put in my very first comment.... "I don't suppose anyone here has the code, or an alternative solution to this? :)"

An alternative such as Calvin gave worked great for me.... yeah i just knew about the attoms.... i did not care how i did it, i was thinking about writing a file to disk or something, but thats BAD programming, then i thought about DDE, in the end i would just ask about code i had seen before... sorry :(

Thanks for your help again guys....

Craig C.
0
 
LVL 10

Expert Comment

by:Lischke
ID: 2710870
Craig, perhaps it is the different languages we speak, so I did not understand the question as you meant it to sound. Perhpas next time...

Calvin, I'll have a look. (btw: Don't press the refresh button of your browser if you don't want to resend your formular data you entered when commenting. For this particular task there's a link on every question page, labeled "Reload question").

Ciao, Mike
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Integration Management Part 2
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

824 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question