Delphi can run only one program instance

Source: Internet
Author: User

Edit in Project/View Source. Using Global atoms in Windows

Global Atom
By adding a global atom to the system, the global atom is maintained by the Windows system. It ensures that each atom is unique and manages its reference count, when the reference count of the global atom is 0, it is cleared from the memory. We use the globaladdatom function to add a string of less than 255 bytes to the global atom and use globalfindatom to check whether the global atom exists, at the end of the program, use the globaldeleteatom function to delete the added global atom. Example:

Program project1;
Uses Windows
Const
Iatom = 'singleapp ';
Begin
If globalfindatom (iatom) = 0 then
Begin
Globaladdatom (iatom );
Application. initialize;
Application. createform (tform1, form1 );
Application. Run;
Globaldeleteatom (globalfindatom (iatom ));
End
Else
MessageBox (0, 'you have run this project', '', mb_ OK );
End.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.