Hackers Guide to Visual FoxPro 7.0
Init, Destroy
These events fire when an object is created and when it's released, respectively. They're similar to the constructor and destructor methods of other OOP languages, but differ from those because they don't actually perform the construction or destruction themselves.| Usage | PROCEDURE oObject.Init [ LPARAMETERS [ nIndex , ] [ ParamList ] ] PROCEDURE oObject.Destroy |
| | This one's a documentation bug, not a product bug, we think. Like many other events, when the control that triggered it is a member of a control array (an array property holding references to objects), Init accepts a numeric parameter indicating which member of the array fired the event. Help doesn't show the nIndex parameter for Init. Destroy, on the other hand, is documented as accepting an nIndex parameter, but it's really hard to tell because it never fires at all. |
Init is also the method to which you can pass parameters when you create an object. For all objects except forms and formsets, this makes a great deal of sense since Init fires first. With forms and formsets, it's somewhat inconvenient because a lot of things happen before you reach the Init. But, we're pleased by the consistency anyway.
There is one case where Load, rather than Init, receives parameters. When you're dealing with a formset converted from FoxPro 2.6 (with WindowType = 2 or 3), parameters go to the Load event, not to Init. You'll often want to hold onto the parameters passed to the Init method. Since the actual parameters themselves are released when the Init method ends, the trick is to create properties of the object and use Init to save the parameter values to the properties. Our example shows how.| Example | * This Init might be for a button. PROCEDURE Init LPARAMETERS cCaption, nTop, cSomethingElse This.Caption = cCaption This.Top = nTop * You need to have added a custom SomethingElse property * to the button for the next line to work. This.SomethingElse = cSomethingElse ENDPROC |
| See Also | Load Event, Unload |
View Updates
Copyright © 2002 by Tamar E. Granor, Ted Roche, Doug Hennig, and Della Martin. All Rights Reserved.
Категории