home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 11 Util / 11-Util.zip / runonce.zip / RunOnce.TXT < prev   
Text File  |  1998-02-23  |  3KB  |  73 lines

  1. TRunOnce Component
  2. ******************
  3. The TRunOnce component allows a program to determine if a previous 
  4. instance of the program is already running and to possibly quit if
  5. a previous instance is determined to be running.  TRunOnce determines
  6. if a previous instance is running by allocating some named shared 
  7. memory.  The name of the memory allocated is the name of the EXE
  8. running with all '.' replaced by 'x' (for instance: TEST.EXE would
  9. equal \SHAREMEM\TEXTxEXE).  Subsequent runs while the original is
  10. still running return a valid value from checking the named memory.
  11. The original program stores window handle of its main form in the
  12. shared memory location so the subsequent programs can refocus the 
  13. window.
  14. Due to where window handles are allocated and available, the 
  15. component does not automatically halt the current instance if a 
  16. previous instance is running.
  17.  
  18. To install:
  19. -----------
  20. Unzip the component source in your component source directory (my
  21. directory is "drv:\sibyl\Components\...".  Compile the source, then move
  22. the 'RunOnce.SPU' to the Sibyl COMPNT directory.
  23. In Sibyl, choose 'Component', then 'install'.  Go to the COMPNT directory 
  24. and select 'RunOnce.SPU'.  Select the TRunOnce component and click OK.
  25. The TRunOnce component/dialog will appear in a tab labeled 'Custom'.  To
  26. change the component location, edit the EXPORTS line in the source.
  27.  
  28. TRunOnce Methods:
  29. -----------------
  30. CheckOnly - Procedure called in the main forms 'OnShow' event to check if 
  31.             it is the only copy of the program running.  This routine does 
  32.             not have to be called if only the knowledge is wanted that the 
  33.             program has a previous instance running.
  34.  
  35. TRunOnce Properties:
  36. --------------------
  37. FirstInst - Read only, BOOLEAN.  Property returns TRUE for first instance
  38.             of program, FALSE for subsequent while first is running. 
  39.             Property is not available during the design stage.
  40.  
  41. UseNotifyMsg - R/W, BOOLEAN.  Property determines if the 'CheckOnly' method
  42.                displays a dialog with a message to the effect that another
  43.                copy of the program is running.  Default is FALSE and the
  44.                property is available during design.
  45.  
  46. NotifyMsg - R/W, STRING.  Property contains the message displayed if the
  47.             UseNotifyMsg property is set to TRUE.  The default message is:
  48.             'Application already running!' and the property is available
  49.             during design.
  50.  
  51. Version - Read only (not stored) STRING.  Property is available during 
  52.           design.  Property returns the current version of the TRunOnce 
  53.           component.
  54.  
  55. To use:
  56. -------
  57. Drop TRunOnce on form during design stage.  Call the CheckOnly method from the
  58. main forms 'OnShow' event.  Note, a message dialog is displayed if the RunOnce
  59. property 'UseNotifyMsg' is set to TRUE.
  60.  
  61. For example-
  62.  
  63.  Procedure TForm1.OnShow(Sender: TObject);
  64.  Begin
  65.    IF RunOnce1.FirstInst
  66.     THEN Caption := Caption + ' - Original';
  67.    RunOnce1.CheckOnly; {keep other instances from running}
  68.  End;
  69.  
  70. Any comments, suggestions, bug fixes, feel free to contact me.
  71.  
  72. - Michael G. Slack (slack@ibm.net), 1998/02/21
  73.