[Lazarus] uniqueinstance
luiz americo pereira camara
luizmed at oi.com.br
Sat May 23 12:27:04 CEST 2015
Check for the property PriorInstanceRunning in FormDestroy
Luiz
2015-05-23 7:12 GMT-03:00 Martin <mailinglists at collins-email.co.uk>:
> Hi,
>
> Just need a little advice on placement of code please, thanks in advance.
>
> I wanted my app to have only one instance, so found uniqueinstance -
> http://wiki.lazarus.freepascal.org/UniqueInstance (it has the ability to
> pass the command line parameters from the second to the first instance
> which is something I want but haven't got round to testing yet!)
>
> There's no problem with uniqueinstance, from reading the source I think
> that it's terminating the second instance before the onshow event of the
> main form so I'm guessing that the formcreate and formdestroy events of the
> main form from the second instance still occur and that's where I think my
> problem is.
>
> I am using the formcreate event to parse the command line arguments to the
> constructor of my main class, which amongst other things unzips files to
> the /tmp directory. I then use the formdestroy to clean up, deleting the
> files in the /tmp directory.
>
> If I start a second instance with the same command line parameters as the
> first, uniqueinstance terminates the second instance and no second form is
> seen on screen. However, all the files are deleted from /tmp (formdestroy)
> so they are no longer available to the first instance so it fails. (I know
> in a real life situation it would be unlikely that the second instance
> would be trying to open the same files as the first, but not impossible.)
>
> So either I use some form of file locking or keep uniqueinstance and move
> my code. I just wanted some advice please, as to where people on the list
> would suggest I put the code to parse the command line parameters to the
> constructor of my main class and/or clean up code. I was looking at some of
> the application events in the myapp.lpr file but I am not sure if that is
> the right place? Any help gratefully received.
>
> Thanks,
>
> Martin Collins
>
> --
> _______________________________________________
> Lazarus mailing list
> Lazarus at lists.lazarus.freepascal.org
> http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20150523/2f81a387/attachment-0003.html>
More information about the Lazarus
mailing list