properly close program

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

Post Reply
franco
Posts: 877
Joined: Sat Nov 02, 2013 5:42 am
DBs Used: DBF
Location: Canada

properly close program

Post 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.
All The Best,
Franco
Canada
edk
Posts: 999
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland

Re: properly close program

Post 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)
franco
Posts: 877
Joined: Sat Nov 02, 2013 5:42 am
DBs Used: DBF
Location: Canada

Re: properly close program

Post 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

All The Best,
Franco
Canada
franco
Posts: 877
Joined: Sat Nov 02, 2013 5:42 am
DBs Used: DBF
Location: Canada

Re: properly close program

Post 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
All The Best,
Franco
Canada
edk
Posts: 999
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland

Re: properly close program

Post 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.
franco
Posts: 877
Joined: Sat Nov 02, 2013 5:42 am
DBs Used: DBF
Location: Canada

Re: properly close program

Post by franco »

Thanks again Edward.
Franco
All The Best,
Franco
Canada
Post Reply