Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Understanding dodefault()
Message
De
15/12/2018 19:28:30
 
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Programmation Orientée Object
Divers
Thread ID:
01664512
Message ID:
01664514
Vues:
60
>Hi came across the following situation:
>
>Say you have the following:
>BASE_FORM that has some code in the LOAD method.
>You create a child form CHILD_FORM based on the BASE_FORM. CHILD_FORM Load method has some code but no DODEFAULT(). Still, the method BASE_FORM.LOAD() fires in the CHILD_FORM.LOAD().
>
>Now say you have a slightly different situation:
>BASE_FORM has some code in the LOAD method.
>You create a child form CHILD_FORM which has no code in the LOAD method.
>You create a GRAND_CHILD_FORM based on the CHILD_FORM. The GRAND_CHILD_FORM.LOAD has some code. The GRAND_CHILD_FORM.LOAD method does not fire the BASE_FORM.LOAD() code. It fire only if you have DODEFAULT() in the GRAND_CHILD_FORM.LOAD().
>
>Why?
>
>TIA

That's because when you put code in the method, you're overriding the parent class code. The DODEFAULT() is required to make sure that the code from the parent class code to be executed. Any code placed before the DODEFAULT() would execute before the code from the parent class, and code after the DODEFAULT() will execute after the parent class code.
DEFINE CLASS Parent_Form AS Form
    PROCEDURE Load
        WAIT WINDOW "Parent_Form.Load()"
    ENDPROC  && Load
ENDDEFINE && Parent_Form

DEFINE CLASS Child_Form AS Parent_Form
ENDDEFINE  && Child_Form

DEFINE CLASS Grandchild_Form AS Child_Form
    PROCEDURE Load
        WAIT WINDOW "before Load()"
        DODEFAULT()
        WAIT WINDOW "After Load()"
    ENDPROC  && Load
ENDDEFINE  && Grandchild_Form
One thing we might try is to define additional methods -- a BeforeSomeEvent and AfterSomeEvent, then in the child classes we don't touch SomeEvent code, but use the BeforeSomeEvent and AfterSomeEvent instead.
DEFINE CLASS Parent_Form AS Form
    PROCEDURE Load
        THISFORM.BeforeLoad()
        WAIT WINDOW "Parent_Form.Load()"
        THISFORM.AfterLoad()
    ENDPROC  && Load

    PROCEDURE BeforeLoad
    ENDPROC  && BeforeLoad

    PROCEDURE AfterLoad
    ENDPROC  && AfterLoad

ENDDEFINE && Parent_Form

DEFINE CLASS Child_Form AS Parent_Form
ENDDEFINE  && Child_Form

DEFINE CLASS Grandchild_Form AS Child_Form
    PROCEDURE BeforeLoad
        WAIT WINDOW "before Load()"
    ENDPROC  && BeforeLoad

    PROCEDURE AfterLoad
        WAIT WINDOW "After Load()"
    ENDPROC  && AfterLoad
ENDDEFINE  && Grandchild_Form
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform