Solved

Simple Easy, Check For Instance Of Running Program

Posted on 2000-04-11
11
300 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 35 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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

776 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