Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Parent property
Message
From
02/05/2002 12:59:13
 
 
To
02/05/2002 12:45:01
General information
Forum:
Visual FoxPro
Category:
Classes - VCX
Title:
Miscellaneous
Thread ID:
00651974
Message ID:
00651982
Views:
20
Hi Ken.

> i set up a new property AA in a class cMYCLASS that i made based on a form. then i create a document form fMYFORM based on the class, this form then changes the AA property value from 1 to 2. later in code i would like to revert the value from 2 back to 1. i dont actually know the values - 1 and 2 are just for demonstration. so, do you guys know a way to access the original cMYCLASS.AA value from the current fMYFORM ?

You'll need to save the old value somewhere and then restore it on demand. This sounds like a classic use of the memento design pattern. The idea of this design pattern is that you ask another object to save something for you and then later ask for it back again. Typical uses are undo/redo, persist/restore, and the case you're asking about.

Here's a very simple implementation of this (this is untested code, so I make no guarantees it'll actually work <g>):
define class cMyClass as Form
    AA = 0
    oMemento = .NULL.

    procedure Init
        This.oMemento = createobject('Memento')
    endproc

    procedure ChangeAA(tnValue)
        This.oMemento.Save(This.AA)
        This.AA = tnValue
    endproc

    procedure RestoreAA
        This.AA = This.oMemento.Restore()
    endproc
enddefine

define class Memento as Custom
    nValue = 0

    procedure Save(tnValue)
        This.nValue = tnValue
    endproc

    procedure Restore
        return This.nValue
    endproc
enddefine
To change the AA property, you don't assign it directly but instead call the ChangeAA method (alternatively, you could have an assign method for the AA property). To restore the saved value, call RestoreAA.

Obviously, this is a very simple implementation that is specific for this application. A more useful memento can store data of any type for any object (possibly multiple levels of values too, so you can restore back to any previous value). However, I hope it serves to illustrate the idea.

Doug
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform