[AccessD] Can a function return an object?

Stuart McLachlan stuart at lexacorp.com.pg
Fri Mar 17 23:43:51 CDT 2023


ChatGPT? <vbg>
(Actually, don't bother it just told me that 
"OBJPTR is not a built-in function in Visual Basic or VBA. "

Whch is strange, because this works :)
Function OBJTest() As Long  
    Dim col As Collection
    Set col = New Collection
    Debug.Print ObjPtr(col)
End Function

As for your link. VB.NET?  .net is on a different planet :)

And essentially, the stuff in that link is a load of badly explained garbage..
(Also, you'll' notice that the last "News" update on that site was 2010!)

This seems to be a fairly good reference at first glance:
http://www.thevbzone.com/secrets.htm


On 18 Mar 2023 at 9:17, Borge Hansen wrote:

> Hi Stuart,
> Interesting information.
> I am amazed about your level of knowledge.
> If I wanted to deepen my knowledge about this particular subject, can
> you give me any pointers / links where I can read more about the
> STRPTR and VARPTR .... Well - I thought to search Google ... here is
> one link: https://classicvb.net/tips/varptr/
> 
> /borge
> 
> On Sat, 18 Mar 2023 at 07:50, 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
> >
> -- 
> 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