Question

I'm trying to control my app instances with JclAppInstances. It works fine, until I don't change my file version in Project Settings. How to make JclAppInstances independent of app file version, so it doesn't let the user to start multiple copies of the application even if the versions are different?

Was it helpful?

Solution

As far as I can tell, the class you're talking about doesn't care about application versions. It bases things on application paths, but then only if you haven't specified a unique application ID yourself.

The TJclAppInstances.InitData method uses this code to initialize the internal application ID:

if ExplicitUniqueAppId <> '' then
  FUniqueAppID := JclAIPrefix + ExplicitUniqueAppId
else
  FUniqueAppID := AnsiUpperCase(JclAIPrefix + ParamStr(0));

ExplicitUniqueAppId is a global variable that starts out empty. If it doesn't get set to anything else, then you can see that the code uses ParamStr(0) to set the application ID. ParamStr(0) returns the full path and file name of your application. If you have multiple versions of your program installed, then they must be in different locations, and that's why it appears that your program is concerned about application versions. In fact, it's just that they're in different locations; the specific versions are irrelevant.

To set ExplicitUniqueAppId to a non-empty value, you need to call the one-argument version of JclAppInstances. It expects the parameter to be an application-specific GUID (which you can generate by pressing Ctrl+Shift+G in the IDE), but it could really be any string of your choosing, so long as it uniquely identifies your application.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top