DELPHI 如何让程序只能运行一次

在你的程序的主FORM 的 FORMCREATE 事件里面添加如下的代码:
procedure TFORM.FormCreate(Sender: TObject);
var
errno:integer;
hmutex:hwnd;
begin
hmutex:=createmutex(nil,false,pchar(application.Title));
errno:=getlasterror;
if errno=error_already_exists then
begin
ShowMessage('程序已经在运行了');
Application.Terminate;
end;
//....这是你原来的代码继续下去

转自:https://zhidao.baidu.com/question/152578179.html

其它方法:http://www.cnblogs.com/huhu0013/archive/2010/09/01/1814943.html [delphi]保证程序只运行一个实例

posted @ 2017-10-26 13:42  stma  阅读(1042)  评论(0)    收藏  举报