Logic
New member
- Katılım
- 19 Haz 2005
- Mesajlar
- 137
- Reaction score
- 0
- Puanları
- 0
unit Unit1;
uses
Windows, Dialogs, Sysutils;
{....}
implementation
{....}
var
mHandle: THandle; // Mutexhandle
initialization
mHandle := CreateMutex(nil, True, 'XYZ');
if GetLastError = ERROR_ALREADY_EXISTS then
begin
ShowMessage('Program is already running!');
halt;
end;
finalization
if mHandle <> 0 then CloseHandle(mHandle)
end.
{******************************************************************}
// 2. CreateSemaphore
// (Alternative Funtion, Alternative Funktion)
// başka bir alternatif
procedure TForm1.FormCreate(Sender: TObject);
var
Sem: THandle;
begin
Sem := CreateSemaphore(nil, 0, 1, 'PROGRAM_NAME');
if ((Sem <> 0) and (GetLastError = ERROR_ALREADY_EXISTS)) then
begin
CloseHandle(Sem);
ShowMessage('This program is already running.');
Halt;
end;
end;
{******************************************************************}
// 3: GlobalFindAtom, GlobalAddAtom
{
This sample shows how to determine if your program was
running in a current session of Windows
It can be usefull if you want ie. to limit your program (a demo)
to run only once per session. It can be stimulating for a registering. :
}
// Place in FormShow event:
procedure TForm1.FormCreate(Sender: TObject);
var
atom: Integer;
CRLF: string;
begin
if GlobalFindAtom('A Text used to be stored in memory') = 0 then
atom := GlobalAddAtom('A Text used to be stored in memory')
else
begin
CRLF := #10 + #13;
ShowMessage('This version may only be run once for every Windows Session.' +
CRLF +
'To run this program again, you need to restart Windows, or better yet:' +
CRLF +
'REGISTER !!');
Close;
end;
end;
Programın ard arda iki kez çalışmasını önlemek için gerek kodlar.
Birde bu yöntem var
procedure TForm1.FormCreate(Sender: TObject);
var
Sem: THandle;
begin
Sem := CreateSemaphore(nil, 0, 1, 'PROGRAM_NAME');
if ((Sem <> 0) and (GetLastError = ERROR_ALREADY_EXISTS)) then
begin
CloseHandle(Sem);
ShowMessage('This program is already running.');
Halt;
end;
end;
end.
bu yöntemde programın ismini değiştirseniz bile yeninden çalıştıramıyorsunuz. ama birinci kodla program ismi değiştiği zaman yeninden çalıştırabilirsiniz. saygılar.
uses
Windows, Dialogs, Sysutils;
{....}
implementation
{....}
var
mHandle: THandle; // Mutexhandle
initialization
mHandle := CreateMutex(nil, True, 'XYZ');
if GetLastError = ERROR_ALREADY_EXISTS then
begin
ShowMessage('Program is already running!');
halt;
end;
finalization
if mHandle <> 0 then CloseHandle(mHandle)
end.
{******************************************************************}
// 2. CreateSemaphore
// (Alternative Funtion, Alternative Funktion)
// başka bir alternatif
procedure TForm1.FormCreate(Sender: TObject);
var
Sem: THandle;
begin
Sem := CreateSemaphore(nil, 0, 1, 'PROGRAM_NAME');
if ((Sem <> 0) and (GetLastError = ERROR_ALREADY_EXISTS)) then
begin
CloseHandle(Sem);
ShowMessage('This program is already running.');
Halt;
end;
end;
{******************************************************************}
// 3: GlobalFindAtom, GlobalAddAtom
{
This sample shows how to determine if your program was
running in a current session of Windows
It can be usefull if you want ie. to limit your program (a demo)
to run only once per session. It can be stimulating for a registering. :
}
// Place in FormShow event:
procedure TForm1.FormCreate(Sender: TObject);
var
atom: Integer;
CRLF: string;
begin
if GlobalFindAtom('A Text used to be stored in memory') = 0 then
atom := GlobalAddAtom('A Text used to be stored in memory')
else
begin
CRLF := #10 + #13;
ShowMessage('This version may only be run once for every Windows Session.' +
CRLF +
'To run this program again, you need to restart Windows, or better yet:' +
CRLF +
'REGISTER !!');
Close;
end;
end;
Programın ard arda iki kez çalışmasını önlemek için gerek kodlar.
Birde bu yöntem var
procedure TForm1.FormCreate(Sender: TObject);
var
Sem: THandle;
begin
Sem := CreateSemaphore(nil, 0, 1, 'PROGRAM_NAME');
if ((Sem <> 0) and (GetLastError = ERROR_ALREADY_EXISTS)) then
begin
CloseHandle(Sem);
ShowMessage('This program is already running.');
Halt;
end;
end;
end.
bu yöntemde programın ismini değiştirseniz bile yeninden çalıştıramıyorsunuz. ama birinci kodla program ismi değiştiği zaman yeninden çalıştırabilirsiniz. saygılar.