References

Description Properties Functions Examples See also






Description


Any variable or object can be made to refer to another variable or object of the same type. A reference is created and destroyed using the method setreference. Any object can be a reference. No special declaration is necessary.
While an object is a reference, reading or setting its value or properties, or calls to its methods are redirected to the referenced object.
After a reference is destroyed, the behavior of the object returns back to normal.
A reference is useful in situations when the actual object is not know a priori, only its type.



Properties


r = isreference;





Methods


Inherited from Object
setreference(refobj);



The argument refobj must be of the same type. If no argument is given, the reference is removed. When a variable refers to another variable, calling its methods or properties and reading or writing its value always apply to the variable referenced.

An element of a vars or pars can be referenced, while an element of an array cannot. Since the KPL language currently doesn't allow constructs such as MyVar[Index1, Index2].method, a reference can be used to call the methods of individual elements of multidimensional variables. For example, the following construct:

RefVar.setreference(MulVar[0, 1]);
RefVar.loadfromfile(FileName);
RefVar.setrefrence;

will load data from file into MulVar[0, 1].




Constants




Examples




See also





(C) 2008-2010 Lorin Milescu. Last modified: 09-01-2010