[AccessD] Can a function return an object?

Stuart McLachlan stuart at lexacorp.com.pg
Fri Mar 17 16:50:02 CDT 2023


Be careful with the word "pointer".
A pointer "points"  to a memory location.
There is a differentce between a pointer and a reference.
You pass a reference to an object instance , not a pointer.

An object reference (reference to an object instance) stays  the same for the life of the 
instance, but theinstance's location in memory  may change.   VBA doesn't expose the 
pointer to it. It's managed behind the scenes 

It's a bit like the difference between VARPTR and STRPTR for dynamic strings.The STRPTR 
will change every time the string is modified so that it moves in memory,  the VARPTR 
remains the same since it is a pointer to a pointer to the string.

In general, all return values are pointers returned in registers which are de-referenced by the 
calling statement.


On 17 Mar 2023 at 16:13, John Colby wrote:

> Technically speaking a function returns a *pointer* to an object.  It
> is a 32 bit or 64 bit number which points to an address in memory
> where the actual instance of the object resides.  This is an important
> distinction because functions can accept and return actual instances
> of *some* things such as an integer variable.  But AFAIK objects are
> never passed, only pointers to objects are passed.
> 
> IIRC the function is defined with the 'as' keywords after it, followed
> by the type of thing being returned, in this case an object of type
> form.
> 
> Function fFrm() As Form
> 
>     Set fFrm = Forms("frmLocation")
> 
> End Function
> 
> Now in the debug window:
> 
> ?ffrm.Caption
> frmLocation
> 
> On Fri, Mar 17, 2023 at 5:56AM Arthur Fuller
> <fuller.artful at gmail.com> wrote:
> 
> > Can a VBA function return an object, such as a form or DAO.database?
> >
> > Can a function return a collection?
> >
> > --
> > Arthur
> > --
> > AccessD mailing list
> > AccessD at databaseadvisors.com
> > https://databaseadvisors.com/mailman/listinfo/accessd
> > Website: http://www.databaseadvisors.com
> >
> 
> 
> -- 
> John W. Colby
> Colby Consulting
> -- 
> AccessD mailing list
> AccessD at databaseadvisors.com
> https://databaseadvisors.com/mailman/listinfo/accessd
> Website: http://www.databaseadvisors.com




More information about the AccessD mailing list