Sign in Join
Wiki copytemporary

Run program once/de: what changed

Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.

Title: Run program once/de

OldNewLine
1+Zurück zur Seite [[code examples/de|Code Beispiele]].
2+
3+Dieser Artikel beschäftigt sich mit der Windowsprogrammierung.
4+
5+Die Funktion prüft, ob sich das Programm bereits gestartet wurde.
6+
7+Für den Fall, dass das Programm bereits gestartet wurde wird ein Hinweis ausgegeben und die neue Instanz des Programms beendet sich von selbst.
8+
9+Der Code wird im Ereignis OnCreate des Hauptformulars aufgerufen.
10+
11+``` pascal
12+uses
13+ SysUtils, Forms, Windows, ...;
14+
15+ ...
16+
17+procedure TForm1.FormCreate(Sender: TObject);
18+begin
19+ // Lässt nur eine Instanz des Programms zu!!
20+ CreateMutex(nil, True, PChar(ExtractFileName(application.ExeName)));
21+ if GetLastError = ERROR_ALREADY_EXISTS then
22+ begin
23+ application.messagebox(PChar('Das Programm läuft bereits!'), 'Achtung', 0 + MB_ICONerror);
24+ application.terminate;
25+ end;
26+end;
27+
28+ ...
29+```
30+
31+---
32+*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](/wiki-contact).*

Back to history