Page 1 of 1

properly close program

Posted: Fri Aug 23, 2024 4:49 pm
by franco
I want to make sure when I close my program all memory and open files are closed and released.
Is there a easy way to close and release all.
I am sure there is a post but I am having a problem locating it.
Thanks in advance.

Re: properly close program

Posted: Sat Aug 24, 2024 1:02 pm
by edk
Normally when you close an application Windows should release the resources used by the application and close all files opened by the application. However, if you want to close all opened dbf files, release unused memory (you won't release all used memory because the application needs it), release all optional dll libraries and terminate the process and threads you can use the code:

Code: Select all

dbcloseall()
RELEASE MEMORY
UnloadAllDll()
ExitProcess(0)

Re: properly close program

Posted: Sat Aug 24, 2024 4:09 pm
by franco
Thanks edk.
This is what I use but wanted to make sure this exits properly.

Code: Select all

 #include "hmg.ch"
  #define CRLF    HB_OsNewLine()
  #include "FILEIO.CH"

  function Main()
	local temp
	public prating := 8, AND MORE

        REQUEST DBFNTX          
        SET CENTURY ON
        SET DELETED OFF
        SET DATE TO BRITISH
        USE CONTROLS NEW SHARED 
        GO 1
        MSERIAL := ALLTRIM(SERIAL)
        USE
	 HB_LANGSELECT( "EN" )

        // Define the main window.
        DEFINE WINDOW Win_1                  ;
           AT         0,0                    ;
           WIDTH      getdesktopWidth()-25      ;
           HEIGHT     getDeskTopHeight()-45  ;
           TITLE      " Title"   ;
	   MAIN                              ;
           NOMAXIMIZE                        ;
           NOSIZE                            ;
	   ON INIT   {||{ ABOUT()} 
           BACKCOLOR  GRAY ;
	   FONT 'Arial' SIZE 9 
	   ON KEY CONTROL + G action MSGBOX('Series: '+mcod)
	   ON KEY CONTROL + W action ABOUT()   
		   
           DEFINE MAIN MENU OF Win_1
              	  POPUP "    E&xit"
                      ITEM "&Exit Q&A" ;
                              ACTION Win_1.Release
           	      END POPUP
              	      POPUP "   MORE POPUPS"
                      ITEM " MORE POPUPS" ;
                              ACTION MORE FUNCTIONS
           	      END POPUP
          END MENU
		     ON KEY F1 OF WIN_1 ACTION HELPING('q&a.HLP')
		     ON KEY F10 OF WIN_1 ACTION MSGBOX('DATE: 02/20/20')
        END WINDOW
        ACTIVATE WINDOW Win_1
	set helpfile to helping('q&a.hlp')

  return NIL


Re: properly close program

Posted: Mon Aug 26, 2024 7:27 pm
by franco
What would be the proper way do the,
Action dbcloseall() , RELEASE MEMORY, win_1.release, UnloadAllDll() ,ExitProcess(0)
or a function

Action Getout(), win_1 release
Function Getout)()
dbcloseall()
RELEASE MEMORY
UnloadAllDll()
ExitProcess(0)
return

Re: properly close program

Posted: Tue Aug 27, 2024 6:52 am
by edk
Releasing the main form is sufficient, it will release all forms and consequently execute the indicated commands.
These commands/functions are worth using in ErrorBlock() when we intend to terminate the application due to errors.

Re: properly close program

Posted: Tue Aug 27, 2024 3:48 pm
by franco
Thanks again Edward.
Franco