|
VFP 愛用者社區 本討論區為 Visual Foxpro 愛用者經驗交流的地方, 請多多利用"搜尋"的功能, 先查看看有無前例可循, 如果還有不懂的再發問. 部份主題有附加檔案, 須先註冊成為社區居民才可以下載.
|
上一篇主題 :: 下一篇主題 |
發表人 |
內容 |
Ruey
註冊時間: 2003-03-12 文章: 1698 來自: tunglo
第 1 樓
|
發表於: 星期五 五月 16, 2003 11:05 pm 文章主題: 釋放所有開啟的表單(轉貼) |
|
|
How can I release all open forms
Summary
This entry is based on the following thread: Coding, syntax & commands Re: Program to close all forms Thread #359746. In order to release all open forms you need to do it backwards through the collection. If the forms use the QueryUnload method to check to make sure the form can release, you'd need to check the results of that as well.
Description
See more info about it at WiKi
********************************************************************
* Description.......: Release all open forms
* Calling Samples...:
* Parameter List....:
* Created by........: George Tasker
* Modified by.......:
********************************************************************
local lnForms, llDone
lnForms = _SCREEN.FormCount
llDone = .T.
DO WHILE lnForms > 0 AND llDone
llDone = _SCREEN.Form(lnForms).QueryUnload()
IF llDone
_SCREEN.Form(lnForms).Release
lnForms = lnForms - 1
ENDIF
ENDDO
This loop would immediately terminate, if one of the form could not be closed, so the rest of forms would be left opened.
This is the code from Nick Neklioudov:
If there is no code in QueryUnload, it can be just like this:
********************************************************************
* Description.......: Release all open forms
* Calling Samples...:
* Parameter List....:
* Created by........: Nick Neklioudov
* Modified by.......:
********************************************************************
local lnForms, i
lnForms = _screen.formcount
FOR i = lnForms to 1 STEP -1
_screen.Forms(i).Release
ENDFOR
Another code is provided by Ed Rauh:
********************************************************************
* Description.......: Release all open forms
* Calling Samples...:
* Parameter List....:
* Created by........: Ed Rauh
* Modified by.......:
********************************************************************
With _Screen
for i = 1 TO .ControlCount
.RemoveObject(.Controls(.ControlCount).Name)
endfor
Endwith
CAUTION This approach would fail in situations, where forms may contain object refs, especially to other Form objects; the reason is that if you fail to release a Form that contains an object ref to another Form, or a control owned by another form, before releasing the referenced Form, the referenced Form will fail to Release as a result of a dangling object ref. i.e:
Form1 is instanced
Form2 is instanced, and holds an object ref to Form1 called Form2.oForm1Ref
If Form2 is released, and then Form1 is released, both Forms release normally
If Form1 is released before Form2, the object ref Form2.oForm1Ref still exists, and the object Form1 is not released, since there's still an active reference to the object Form1. If Form2 is now released, a dangling object Form1 remains with no means to clean it up and close normally. In order to find the dangling object reference you can use David Frankenbach utitlity (available for download from his site)
Thanks to Ed Rauh for this warning
In addition, the following code may be used: ( see
Coding, syntax & commands Re: How to Abort Thread #448407 Message #448450)
********************************************************************
* Description.......: Depart
* Calling Samples...:
* Parameter List....:
* Created by........: Ed Rauh
* Modified by.......:
********************************************************************
FUNCTION Depart
LPARAMETER tlNoDebug
CLEAR EVENTS
POP KEY ALL
SET ASSERTS ON
ON SHUTDOWN
DEACTIVATE WINDOW ALL
_SCREEN.Hide()
SET SYSMENU TO DEFAULT
SET LIBRARY TO
ASSERT _SCREEN.Show() AND ''=SYS(3056) AND tlNoDebug 'Forms Deactivated'
WITH _SCREEN
DO WHILE .FormCount > 0
.Forms(.FormCount).Release()
ENDDO
ENDWITH
ASSERT tlNoDebug 'Forms Released'
RETURN .F.
With dangling object refs, you still may need a CLEAR ALL. |
|
回頂端 |
|
|
CPS0204
註冊時間: 2014-08-24 文章: 441
第 2 樓
|
發表於: 星期日 一月 10, 2016 5:07 pm 文章主題: |
|
|
local lnForms, llDone
lnForms = _SCREEN.FormCount
llDone = .T.
DO WHILE lnForms > 0 AND llDone
llDone = _SCREEN.Form(lnForms).QueryUnload()
IF llDone
_SCREEN.Form(lnForms).Release
lnForms = lnForms - 1
ENDIF
ENDDO
*******************
上方紅字,需改為FORMS 才可在VFP9 執行無誤! |
|
回頂端 |
|
|
|
|
您 無法 在這個版面發表文章 您 無法 在這個版面回覆文章 您 無法 在這個版面編輯文章 您 無法 在這個版面刪除文章 您 無法 在這個版面進行投票 您 無法 在這個版面附加檔案 您 無法 在這個版面下載檔案
|
|