[AccessD] Can a function return an object?

John Colby jwcolby at gmail.com
Fri Mar 17 18:37:15 CDT 2023


** In general, all return values are pointers returned in registers

So the function returns a pointer?

My understanding from back in assembler days is that params into a function
are stored on the stack, and return values are popped off the stack. Not
that I've done any assembler since the 80s.

In any event AFAICT the returned value points to the current location of
the object.  Whether it is 'de-referenced' by the caller is another issue
and one that I don't have any expertise in.

I will go out and read about the difference between a pointer and a
reference, something I had never really thought about.  I always used the
two terms loosely and similarly..

On Fri, Mar 17, 2023 at 5:50 PM Stuart McLachlan <stuart at lexacorp.com.pg>
wrote:

> 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
>
>
> --
> AccessD mailing list
> AccessD at databaseadvisors.com
> https://databaseadvisors.com/mailman/listinfo/accessd
> Website: http://www.databaseadvisors.com
>


-- 
John W. Colby
Colby Consulting


More information about the AccessD mailing list