Page 1 of 1

(x)harbour class - destroy method

Posted: Tue Jan 01, 2008 7:03 am
by nageswaragunupudi
I see some classes in FWH have a method by name Destroy(). If we name a method as Destroy, will it be called automatically, when the object goes out of reference ?

xharbour documentation mentions about DESTROYER method. Does it also called automatically?

Can any one clarify please?

Posted: Tue Jan 01, 2008 8:33 am
by Antonio Linares
Nageswararao,

>
I see some classes in FWH have a method by name Destroy(). If we name a method as Destroy, will it be called automatically, when the object goes out of reference ?
>

FWH automatically calls method Destroy() when a windows msg WM_DESTROY arrives:

http://msdn2.microsoft.com/en-us/library/ms632620.aspx

>
xharbour documentation mentions about DESTROYER method. Does it also called automatically?
>

FWH does not uses those methods, in order to have full control of what it is happening in the application

Posted: Tue Jan 01, 2008 9:33 am
by nageswaragunupudi
I have some related doubts about releasing objects like fonts, brushes etc. Normally I place the commands release fonts and other objects after the main (mdi) window's activate command. Example

Code: Select all

func main()

define window ownd MDI ....
.........
activate window ownd
release font ...
release brush ...
return 0

1) IF somewhere in one of the modules if we call WndMain():End(), does the control go to the statements after the main window's activate command and execute all release commands?
2) If somewhere in one of the modules if we issue the statement QUIT, is there the danger that the resources are not destroyed/ released?
if so, is it good to keep the release statements in the EXIT PROCEDURE ?

Or is it desirable that all FWH classes for the resources have a destroy method, so that all the resources are destryoyed / released when the program terminates?

Posted: Tue Jan 01, 2008 10:59 am
by Enrico Maria Giordano
nageswaragunupudi wrote:1) IF somewhere in one of the modules if we call WndMain():End(), does the control go to the statements after the main window's activate command and execute all release commands?
Yes.
nageswaragunupudi wrote:2) If somewhere in one of the modules if we issue the statement QUIT, is there the danger that the resources are not destroyed/ released?
Yes. Example:

Code: Select all

#include "Fivewin.ch"


FUNCTION MAIN()

    LOCAL oWnd

    DEFINE WINDOW oWnd

    @ 1, 1 BUTTON "Test";
           SIZE 100, 20;
           ACTION oWnd:End() //MYQUIT()

    ACTIVATE WINDOW oWnd

    ? "Exiting"

    RETURN NIL


STATIC FUNCTION MYQUIT()

    QUIT

    RETURN NIL
nageswaragunupudi wrote:if so, is it good to keep the release statements in the EXIT PROCEDURE ?
How an EXIT PROCEDURE could see all the variables used in the app for keeping reference of font, brush, etc.? It seem a bad idea.

Maybe the easier solution is to not use QUIT at all.

EMG

Posted: Tue Jan 01, 2008 5:07 pm
by Antonio Linares
Nageswararao, Enrico,

> Maybe the easier solution is to not use QUIT at all.

Right. QUIT should not be used at all.