均在dpr文件中处理。
法1:原子法。
program Project1;
uses
; Forms,
; windows,
; Dialogs,
; Unit1 in 'Unit1.pas' {Form1};
{$R *.RES}
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
; ; showmessage('have one');
end.
法2:信号量法
program Project1;
uses
; Forms, Windows,
; dialogs,
; Unit1 in 'Unit1.pas' {Form1};
var
; Mutex: THandle;
{$R *.RES}
begin
; Mutex := CreateMutex(nil, True, 'Form1');
; if GetLastError <> ERROR_ALREADY_EXISTS then
; begin
; ; Application.Initialize;
; ; Application.CreateHandle;
; ; Application.CreateForm(TForm1, Form1);
; ; Application.Run;
; end
; else
; ; showmessage('have one');
; ReleaseMutex(Mutex);
end.