Page 1 of 1

Is there a function that closes all open or used files?

Posted: Sun Nov 20, 2022 8:42 pm
by Eugene Lutsenko
hi!
Is there a function that closes all open or used files?

There are wonderful functions: CLoseAll() and Close AllWindows(). But we also need the CloseAllFiles() function

Code: Select all

******************************************************************************************
Function CLoseAll()            // Закрытие всех баз данных с ожиданием завершения операций
******************************************************************************************
LOCAL bError , aWorkareas , x, y

bError := ErrorBlock( {|e| Break(e)} )
aWorkAreas := workspacelist()
y := len(aWorkAreas)

for x = 1 to y
  BEGIN SEQUENCE
    (aWorkAreas[x])->(DbClearRelation())
    (aWorkAreas[x])->(DbCloseArea())
  ENDSEQUENCE
next
ErrorBlock(bError)
bError   := nil
Return nil

Code: Select all

************************************************************************************
******** Закрыть все процессы от Роджера
************************************************************************************
FUNCTION CloseAllWindows()

LOCAL i, aChildList, nSeconds := Seconds()

DO WHILE !Empty( aChildList := Set_MainWindow():drawingArea:childList())

  FOR i := 1 TO Len(aChildList)
    IF !aChildList[i]:isDerivedFrom('XbpDialog')
      aChildList[i]:destroy()
    ELSE
      PostAppEvent(xbeP_Close,,,aChildList[i])
    ENDIF
    Sleep(10)
  NEXT

  IF Seconds() - nSeconds > 10
    EXIT
  ENDIF

ENDDO

Sleep(10)

RETURN nil
************************************************************************************

Re: Is there a function that closes all open or used files?

Posted: Sun Nov 20, 2022 11:50 pm
by Auge_Ohr
hi Eugene,

there is a "wonderful" Function : QUIT

IMHO it is recommend to "close DBF" as soon as possible when not need any more

Re: Is there a function that closes all open or used files?

Posted: Mon Nov 21, 2022 1:02 am
by Tom
Don't forget: Workareas are thread-local.

Re: Is there a function that closes all open or used files?

Posted: Mon Nov 21, 2022 1:03 am
by Eugene Lutsenko
Hi, Jimmy!

Of course, the QUIT function is definitely wonderful. but it has one drawback: it causes the program to stop working. And I need a similar function that I want to use before going to the main menu of my system

Re: Is there a function that closes all open or used files?

Posted: Mon Nov 21, 2022 2:26 am
by skiman
Hi,

That closeall() function closes all the files in the current thread. If you execute it before returning to your main menu, everything should be closed.

Re: Is there a function that closes all open or used files?

Posted: Mon Nov 21, 2022 3:00 am
by Eugene Lutsenko
skiman wrote: Mon Nov 21, 2022 2:26 am Hi,

That closeall() function closes all the files in the current thread. If you execute it before returning to your main menu, everything should be closed.
Databases are index arrays, yes. And just busy (open) files?

Re: Is there a function that closes all open or used files?

Posted: Wed Nov 23, 2022 10:49 pm
by Eugene Lutsenko
hi, Roger!

Is it possible to make your CLoseAllWindows() function not give errors if there are no open windows?

Re: Is there a function that closes all open or used files?

Posted: Wed Nov 23, 2022 11:48 pm
by Tom
Just embed in a sequence:

Code: Select all

LOCAL bError := ErrorBlock({|e|Break(e)})
BEGIN SEQUENCE

(do what you want that should not create runtime errors, maybe "CloseAllWindows")

END SEQUENCE
ErrorBlock(bError)

Re: Is there a function that closes all open or used files?

Posted: Wed Nov 23, 2022 11:54 pm
by Eugene Lutsenko
Thank you, Tom! How did I not guess myself:) Probably because it's easier to ask you than to think for yourself