[solved] prevent multiple instances lazarus / 61-Beginners ---------------------------------------------------------------------- HobbyDev · 2017-03-22 20:48 Hello, I am still trying to switch from Delphi to Lazarus. Now I run into an other problem. I want to make sure the application can only run once at a time. With Delphi I used this code: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i var hPrevWin : HWND;    Mutex    : THandle;    RegisterError : integer;  MutexError    : integer; begin  MyMsg := RegisterWindowMessage('Call_First_Arbeitszeiterfassung_Instance');  RegisterError := GetLastError;  Mutex := Crea]"]>Blockedtex(nil, True, 'My_Unique_Application_Mutex_Name');  MutexError := GetLastError;  if (Mutex = 0) OR (MutexError = ERROR_ALREADY_EXISTS) then    begin      SendMessage(HWND_BROADCAST, MyMsg, 0, 0);      Halt(0);    end  Else  begin      Application.Initialize;      Application.Title := 'AZE';    Application.CreateForm(TForm1, Form1);      Application.CreateForm(TLogBookDlg, LogBookDlg);      if MyMsg = 0 then        Application.Messagebox(PChar(InttoStr(RegisterError)),'Registering Window Message',mb_OK);      Application.Run;      if Mutex <> 0 then        FileClose(Mutex); { *Konvertiert von CloseHandle* }    end; end. But Lazarus does not understand the "RegisterWindowMessage" and "Mutex" stuff. Does anyone has an example how to prevent an application to have multiple instances? Thanks in advanced! ---------------------------------------------------------------------- Zoran · 2017-03-22 20:58 See this: http://wiki.freepascal.org/UniqueInstance ---------------------------------------------------------------------- HobbyDev · 2017-03-22 21:09 That looks great! I will check it out! Thank you very much. I just used the wrong words while searching ---------------------------------------------------------------------- Fred vS · 2017-03-22 21:55 Hello. There is also this one: https://github.com/fredvs/runonce_postit Fre;D ---------------------------------------------------------------------- HobbyDev · 2017-03-23 21:11 Today I tested the "UniqueInstance" Component. In the testraw project I placed the component, defined all the properties and compiled it successfully. But the application itself has a size of 14MB. While trying to start an other instance I get some Error Messages (see attachment). Same Error shows up, when I exit the application via the cross in the upper right corner - not using the "Crash Application" Button Did I miss anything? ---------------------------------------------------------------------- RAW · 2017-03-23 21:33 That's funny... That is not an error message, it's the simple version of FastMM4 ... Do you recognize the "CHANGE BUILD MODE"-Button? Just use it to create DEBUG and RELEASE-Mode... ---------------------------------------------------------------------- wp · 2017-03-23 21:34 This is not an error. It is just the message that heaptrc did not find any memory leaks. The only problem is that the testraw project is compiled with the heaptrc option on. Open the "Project Options", "Compiler Options" -> "Debugging" and remove the checkmark of "Use heaptrc unit". It is certainly a left-over of testing the component. As for the size of program, you should seek the forum for similar questions - it is one of the most-often asked questions here, I don't want to repeat the answer... To remove the debugger info (which causes this large exe size) you can check "Use external gdb debug symbols file" on the same project options page to bring the exe size down to about 1.5 MB. ---------------------------------------------------------------------- RAW · 2017-03-23 21:50 If you like to use a MUTEX you can do it like this ... For example: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i PROGRAM UNIQUEWAVE; {$MODE OBJFPC}{$H+}  USES  Interfaces,  SysUtils,  Forms,  Windows,  uUNIQUEWAVE;   {$R *.RES}  CONST  MutexName = 'UNIQUEWAVE MuTeX';  VAR  hMutex: THandle; BEGIN Try  hMutex:= Crea]"]>Blockedtex(Nil, True, MutexName);    If GetLastError = ERROR_ALREADY_EXISTS   Then    Begin     CloseHandle(hMutex);     Exit;    End;   Try   RequireDerivedFormResource:= True;    Application.Title:= 'UNIQUEWAVE';    Application.Initialize;     wndGUI:= TwndGUI.Create(Application); //no need for a TaskbarButton   wndGUI.Show;    Application.Run;  Finally   If hMutex <> 0   Then CloseHandle(hMutex);  End; Except  On E: Exception  Do wndGUI.Log('MAIN PRG'+sLineBreak+E.ClassName+sLineBreak+E.Message, True); End;END. ---------------------------------------------------------------------- RAW · 2017-03-24 00:03 Just in case you didn't know... If you like small EXE-Files and less RAM usage then you can check out this: LLCL LightLCL (Windows only) https://github.com/FChrisF/LLCL Very easy to use: Download, Extract, Add the path: COMPILER OPTIONS: OtherUnitFiles, Check the used Units: not all LCL-Units are supported... Done... Compile... fpGUI (cross platform) http://fpgui.sourceforge.net/ https://github.com/graemeg/fpGUI https://github.com/graemeg/fpGUI/blob/master/extras/freetype_windows/f reetype.zip Very easy to use too: Download, Extract, Open ..src\corelib\fpgui_toolkit.lpk (Open Package File), Click on compile.. done Now you can start a new project and click on PROJECT: Project Inspector: click ADD, click New Requirement and choose fpgui_toolkit, hold LCL or delete it. The Unit names are different with fpGUI, but there are a lot of examples... and CTRL+Space should help... (for example type: fpg_ and press CTRL+Space) There are three things that come to my mind when I read fpGUI: First: smaller EXE-Files and RAM usage Second: Themed programs, same look on all platforms Third: AGG PAS, TAGG2D, semitransparent pixels (of course there is another very popular library for semitransparent pixels: BGRABitmap).. both libs got a lot of examples.. very nice... hot hot hot... ---------------------------------------------------------------------- HobbyDev · 2017-03-24 19:46 Many Thanks to all. In the first step I got rid of the "Error- Message". Thanks for sample code with Mutex as well!