VBScript class Q: Self-assignment of an object to a property from within the same class?

G

Guest

This is a semi-advanced question about ASP VBScript 5.0 classes. If you're
knowledegable, please lend a hand!

VBScript class instances can have properties that have objects assigned to
them. Borrowing R.Quinn's example from ASP101:

Public Property Get Authors()
if not isobject(m_Authors) then
set Library = New cLibrary
Call Library.GetAuthorsByBookID(Me.ID)
set m_Authors = Library.Authors
Set Library = nothing
end if
Set Authors = m_Authors
End Property

In this example, a collection of authors is assigned to property Authors by
calling an method of another class and using the "Set" keyword. This sort of
"external" loading of an object is characteristic of using the Set command.

I want to know if it is possible to assign a complex object to a property
without calling to an external class. For example, it would be elegant if I
could call a private GetAuthors method of the same class somehow (versus
using cLibrary), and pass the resulting object back to the Property.

Is this possible? Can someone get me started with the syntax of this?

Thanks.

-KF
 
D

dlbjr

You have your three options to use with properties.

Property Get
Property Let
Property Set

I believe you are wanting the Property Set to pass the object in.

'dlbjr
'Pleading sagacious indoctrination!
 
G

Guest

Thanks, dlbjr, I know that part. What I'm wondering is if you can pass an
object generated from a private method that's in the same class, and perhaps
hoping that someone has an example of syntax for how you make that happen.

I've read contradictory things concerning whether this is even possible in
ASP VBScript.

-KF
 
G

Guest

Here' s some code illustrating what I'm trying to do. I haven't tested it
yet, so I really don't know how this is going to work, nor do I know if it's
the best practice, but... The class name that I'm calling this from is
clsArticle - it briefly instantiates another instance to grab a value
generated by a method. In anyone knows whether this is "right", or if it's
gonna break, please let me know.

Public Property Get Authors()
if not isobject(m_Authors) then
set ArticleInstance = New clsArticle
' attemping to call this page's own GetAuthorsByArticleID method by
instantiating another instance of clsArticle
Call ArticleInstance.GetAuthorsByArticleID(Me.ID)
set m_Authors = ArticleInstance.Authors
Set ArticleInstance = nothing
end if
Set Authors = m_Authors
End Property
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top