Today, Delphi is one of the popular desktop programming tool. There are thousand even million programmer in this world using delphi as their favorit tool. This site try to collect the examples, tips and tricks of Delphi programming. We collect, test them and redistribute the collection of delphi programming for you.

Check If Application Already Open

Author: admin | Category: Form, Tips and Tricks

//This is delphi example how to Check If Application Already Open
//Create new application then leave the Unit1 as what is it
//Show the units with Ctrl+F12 then choose Project1 Unit
//Use this code then compile your application
//Now your application won't run twice or more
 
program Project1;
 
uses
  Forms,
  Unit1 in 'Unit1.pas' {Form1},
  Windows;
 
{$R *.res}
 
//begin
//  Application.Initialize;
//  Application.CreateForm(TForm1, Form1);
//  Application.Run;
//end.
 
var
appMutex:THandle;
begin
  appMutex := CreateMutex(nil,true,'MUTEX');
  if GetLastError <> ERROR_ALREADY_EXISTS then
  begin
    Application.Initialize;
    Application.Title := 'MUTEX';
    Application.CreateForm(TForm1, Form1);
    Application.Run;
  end;
end.

Tags: ,