Recent

Author Topic: Allow single instance only - and application switching  (Read 6541 times)

wizbowes

  • New Member
  • *
  • Posts: 24
Allow single instance only - and application switching
« on: August 13, 2013, 12:03:42 am »
I want to ensure that only one instance of my application runs, and instead of opening a second application instance, the first application instance is given focus.

Using the UnqiueInstance package I'm able to detect a previous running instance and shut the new instance down.  I can't work out how to activate the initial application.  Solution needs to be platform independent (at least Windows and Mac).

Any ideas gratefully received.

esvignolo

  • Full Member
  • ***
  • Posts: 158
  • Using FPC in Windows, Linux, Macos

LuizAmérico

  • Sr. Member
  • ****
  • Posts: 458
Re: Allow single instance only - and application switching
« Reply #2 on: August 14, 2013, 12:20:42 am »
Using UniqueInstance component, the first application can detect when a second is started with the OnOtherInstance event.

See demo in testcomponent method TForm1.UniqueInstance1OtherInstance


wizbowes

  • New Member
  • *
  • Posts: 24
Re: Allow single instance only - and application switching
« Reply #3 on: August 15, 2013, 10:42:58 am »
Many thanks.  I was just including the unit in my project - but have installed the component now.  However I have a couple of issues:

1)  When using the example project I get the following error (on Windows) when the application close (either via closign but itself, or when it detects another instance and shits itself):

Error:  Heap dump by heaptrc unit. 

2)  If I create a new project, add the component and run it - it works fine.  When I then save the project and try to run it again, I get the errors below in the build.  I presume it's a path issue but couldn't see how to resolve this as I've added the UniqueInstance path to the project paths:

Code: [Select]
Options changed, recompiling clean with -B
UniqueInstance.lpr(20,1) Error: Undefined symbol: DEBUGINFO_UNIQUEINSTANCE
UniqueInstance.lpr(20,1) Error: Undefined symbol: DEBUGSTART_UNIQUEINSTANCE
UniqueInstance.lpr(20,1) Error: Undefined symbol: DEBUGEND_UNIQUEINSTANCE
UniqueInstance.lpr(20,1) Error: Undefined symbol: THREADVARLIST_UNIQUEINSTANCE
UniqueInstance.lpr(20,1) Error: Undefined symbol: VMT_UNIQUEINSTANCE_TUNIQUEINSTANCE
UniqueInstance.lpr(20,1) Fatal: There were 5 errors compiling module, stopping

Many thanks,

User137

  • Hero Member
  • *****
  • Posts: 1791
    • Nxpascal home
Re: Allow single instance only - and application switching
« Reply #4 on: August 15, 2013, 01:22:58 pm »
Try adding uniqueinstance package in Project inspector dependencies.

wizbowes

  • New Member
  • *
  • Posts: 24
Re: Allow single instance only - and application switching
« Reply #5 on: August 16, 2013, 12:57:28 am »
It was there.  Deleted and re-installed 3 times and finally it worked.

Thanks for your assistance.

 

TinyPortal © 2005-2018