Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How much of your code do you test?
Message
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00721300
Message ID:
00722185
Views:
28
>>Hi Larry,
>>
>>No, if the property is bound to the method/event, VFP 8 does the implicit _ASSIGN for the property. Here is the sample similar to what I showed at my VFP 8 presentation in Chicago:
>>
>>
>>*   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
>>
>>
>
>Thanks a lot for the sample. Really nice!

You are welcome.

There is quite a lot you can do with BINDEVENT() function.
For example, the custom forms docking, demonstrated at DevCon as a feature of VFP 9 (Europa) can be easily done in VFP 8 using BINDEVENT() and a few lines of code.
Nick Neklioudov
Universal Thread Consultant
3 times Microsoft MVP - Visual FoxPro

"I have not failed. I've just found 10,000 ways that don't work." - Thomas Edison
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform