Objects Parameters Are Passed by ReferenceID: Q130834 3.00 WINDOWS The information in this article applies to:
SUMMARYBy default, parameters are passed by value to user-defined functions and by reference to procedures called with a DO command. This article explains how an Object-type variable is passed as a parameter.
MORE INFORMATIONObject variables are always passed by reference to user-defined functions and procedures. Creating an object creates a reference to an object of a class. When a procedure or a method receives an object as a parameter, any change made to the parameter affects the object. Only one instance of the object actually exists; the parameter points to the same object as the instance variable. To pass an Object reference from a form, you can use this syntax:
In the following example code, a form is created, and the ChangeCaption
method of the form is called. Controls are passed as parameters. This
example could have been programmed differently by making the ChangeCaption
a method of any control. It is included to illustrate how object type
variables are passed as parameters.
Sample codePUBLIC oForm oForm=CREATEOBJECT('Myform') oForm.show =MESSAGEBOX('Note the Caption of the CommandButton') oForm.ChangeCaption(oform.mycmd) =MESSAGEBOX('Note the Caption of the CommandButton') DEFINE CLASS myform as FORM
ENDDEFINE
DEFINE CLASS cmdquit as COMMANDBUTTON ENDDEFINE
Additional reference words: 3.00 VFoxWin KBCategory: KBSubcategory: FxprgClassoop
|
Last Reviewed: May 22, 1998 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |