proje dosyasında (project1.dpr)
beginden sonra
Kod: Tümünü seç
if (HPrevInst <> 0) then
Exit;
Kod: Tümünü seç
program Project1;
uses
Forms,
windows, // Mutex fomksiyonu için
sysutils, // Uppercase ve ExtractFileName fonksiyonları için
dialogs, // Showmessage için sadece
Unit1 in 'Unit1.pas' {Form1};
{$R *.res}
var hMyMutex : tHandle;
begin
hMyMutex := CreateMutex (nil, True,pChar (Uppercase (ExtractFileName (Application.ExeName))));
if (hMyMutex = 0) or (GetLastError = error_Already_Exists) then
begin
showmessage('aynı anda iki program çalıştıramazsınız');
Application.Terminate;
end;
try
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.Run;
finally
ReleaseMutex (hMyMutex);
end;
end.
tabi exe adını değiştirip onu çalıştırıldığı zaman buda yemiyor.

Kod: Tümünü seç
program Project1;
uses
Forms,
windows, // Mutex fomksiyonu için
sysutils, // Uppercase ve ExtractFileName fonksiyonları için
dialogs, // Showmessage için sadece
Unit1 in 'Unit1.pas' {Form1};
{$R *.res}
var hMyMutex : tHandle;
begin
hMyMutex := CreateMutex (nil, True,pChar (Uppercase (ExtractFileName (Application.ExeName))));
if (hMyMutex = 0) or (GetLastError = error_Already_Exists) then
begin
showmessage('aynı anda iki program çalıştıramazsınız');
Application.Terminate;
end;
// Form1.Caption tasarım anında boş olmalı. Form Createde eklenmeli
if FindWindow(Nil, 'Deneme Form1') <> 0 then
begin
showmessage('Lütfen ikinci exeyi silin! aynı anda iki program çalıştıramazsınız');
Application.Terminate;
end;
//Form1'in Create olayına
//Form1.Caption:='Deneme Form1';
try
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.Run;
finally
ReleaseMutex (hMyMutex);
end;
end.
