Easily Remove Objects After Debugging

Version: 1.01.10 - last update: Saturday, September 26, 2009, 17:30:00

Previous EntryTips & Tricks HomeNext Entry

This is a small but useful debugging enhancement your may want to add to some of your VFP classes.

Intro

While developing your classes you frequently want to test them on the fly. In such scenarios the VFP Class Browser comes in handy. You can instantiate your work in progress from there by simply drag & drop the classes you want to test to VFP's desktop (of course they have to be GUI-classes). After that you’ll end up with new screen members because the Class Browser added your controls using the _SCREEN.NEWOBJECT() method. After testing you may want to resume coding your classes, so you have to reopen them. If a class instance is still in memory VFP tries to clear it for you (what you have to confirm), and sometimes VFP will fail doing so. The number one reason for this is that there are outstanding references left. In such a case if you don’t want to do a CLEAR ALL after having finished testing you have to remove all of your control instances using commands like the following:

_SCREEN.REMOVEOBJECT("cMyNewSuperContainerClass1") 
Nothing wrong with that, but sometimes it can be a real pain in the neck to remember all the class names (and numbering) while keying them in.
Here’s a little code fragment you can put into the RightClick event of those classes (or in any other mouse click more suitable for you)
PROCEDURE RightClick
    TRY
        THIS.PARENT.REMOVEOBJECT(THIS.NAME)
    CATCH
        *\\ Maybe better to do a CLEAR ALL pretty soon!
        WAIT WINDOW "Cannot remove " + THIS.NAME + ;
        " from " + THIS.PARENT.NAME
    ENDTRY
ENDPROC
Try it: Drag&drop some container based class from your Class Browser onto VFP’s desktop.
Call whatever methods you like to test. Finally right click the container instance and your done. 

Previous EntryTips & Tricks HomeNext Entry

No comments:

Post a Comment