>>* If you bind your form controls to properties of a SCATTER NAME object >>* you can put all your data validation logic into the methods >>* of a business logic object, rather than put the code in the Valid() events >>* of the textboxes or other controls >> >>PUBLIC oScatteredRecord, oHandler >>STORE NULL TO oScatteredRecord, oHandler >> >>CLEAR >>CREATE CURSOR _cTest (units Y, unit_price Y, line_total Y) >>APPEND BLANK >>REPLACE units WITH 1, unit_price WITH 2.95 >> >>SCATTER NAME oScatteredRecord >>USE IN _cTest >> >>oHandler = CREATEOBJECT('EvtHandler', oScatteredRecord) && create event handler object >>* and pass the scattered record object to it. >>* Syntax: >>* BINDEVENT(oEventSource, cEvent, oEventHandler, cDelegate [, nFlags]) >> >> >>* Now we bind the property to the method/event >>* If you specify a property name as the cEvent parameter, >>* VFP8 binds an implicit _ASSIGN method for that property. >>* When the value of the property changes, Visual FoxPro fires the bound method/event. >> >> >>BINDEVENT(oScatteredRecord, 'units', oHandler, 'Recalc', 1) && 1 means Execute event code before the delegate code. >>BINDEVENT(oScatteredRecord, 'unit_price', oHandler, 'Recalc', 1) && 1 means Execute event code before the delegate code. >> >>* Now try to change the oScatteredRecord object .units or .unit_price properties and >>* watch the results on screen or in Watch window >> >>oScatteredRecord.units = 2.0 >>? oScatteredRecord.line_total && shows 5.9000 >> >>oScatteredRecord.units = 30 >>? oScatteredRecord.line_total && shows 88.5000 >> >>oScatteredRecord.units = 5 >>? oScatteredRecord.line_total && shows 14.7500 >> >>oScatteredRecord.unit_price = 8.50 >>? oScatteredRecord.line_total && shows 42.5000 >> >> >>DEFINE CLASS EvtHandler AS CUSTOM >> oRec = NULL && holds the reference to event source object >> >> PROCEDURE INIT >> LPARAMETERS toRec >> THIS.oRec = toRec >>ENDPROC >> >> PROCEDURE Recalc && the method which supposed to be bound to properties >> WITH THIS.oRec >> .line_total = .units * .unit_price >> ENDWITH >>ENDPROC >>ENDDEFINE >> >>* There are different ways to do this. For example, >>* the business logic can be placed right into oScatteredRecord object methods >>* The handler object separate from the oScatteredrecord record object >>* may have the advantage that you can change one business logic object to another one without >>* touching the record object, just by unbinding/re-binding the corresponding objects' properties/events >> >>>