Sign in Join
Wiki copytemporary

Run program once/de

Zurück zur Seite Code Beispiele.

Dieser Artikel beschäftigt sich mit der Windowsprogrammierung.

Die Funktion prüft, ob sich das Programm bereits gestartet wurde.

Für den Fall, dass das Programm bereits gestartet wurde wird ein Hinweis ausgegeben und die neue Instanz des Programms beendet sich von selbst.

Der Code wird im Ereignis OnCreate des Hauptformulars aufgerufen.

pascal
uses
  SysUtils, Forms, Windows, ...;

  ...

procedure TForm1.FormCreate(Sender: TObject);
begin
   // Lässt nur eine Instanz des Programms zu!!
   CreateMutex(nil, True, PChar(ExtractFileName(application.ExeName)));
   if GetLastError = ERROR_ALREADY_EXISTS then
   begin
      application.messagebox(PChar('Das Programm läuft bereits!'), 'Achtung', 0 + MB_ICONerror);
      application.terminate;
   end;
end;

  ...

From the Free Pascal wiki, page "Run program once/de", as it stood on 2020-02-25 after a change by Trev, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's Licensing page. If you have concerns about this material, message the admin.

Revision 1, last changed by WikiArchive .

Talk about this page

Nobody has opened a bench for this page yet. Sign in to open one.