Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
Classic ASP Professional For advanced coder questions in ASP 3. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old March 12th, 2006, 01:55 PM
Registered User
Join Date: Mar 2006
Location: , , .
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default Referencing the object that invoked a method

I want individuals who create an object of MyClass to be able to view all the properties and the property values. Also, it's handy to be able to write out the properties of an object and their values just for debugging purposes. Of course, having written the class definition myself, I know all the properties of the class, but one of the fundamental principles of object oriented programming is encapsulation (restricting access or hiding some of the object's data).

Most OOP languages have a mechanism to reference the object that invokes a method within the invoked method. Many languages use the "this" keyword to allow for an invoked method to reference the invoking object.

If it were possible in VBScript, then it would also be possible to use the "For...each" language construct of to iterate the object and write out all it's properties and values.

Specifally, this would allow me to write a "Print" method that does not require future modification even if the properties of MyClass are changed (i.e. adding properties or remving properties). Such a "Print" method would automatically scale with future property changes to the MyClass.

Here is the class definition VBScript/Psuedo:
Class MyClass

    Private m_strValue1
    Private m_strValue2
    Private m_lngValue1

    Private Sub Class_Initalize()
        m_strValue1 = "one"
        m_strValue2 = "two"
        m_lngValue1 = 1
    End Sub

    Public Sub Print()
        For Each x in (ref. to the object that invoked this method)
            'Code to access object properties and property values
    End Sub

End Class

Here is the class implementation VBScript/Psuedo:
Dim myObj

Set myObj = New MyClass
myObj.Value1 = "hello world"
Set myObj = Nothing

Here would be the expected output:
m_strValue1 = one
m_strValue2 = two
m_lngValue1 = 1

Notice the "(ref. to the object that invoked the method)" in the class definition... is there a mechanism in VBScript that will allow for this type of reference?

If so, what is it?

Thanks for any help

Similar Threads
Thread Thread Starter Forum Replies Last Post
Number of variables referencing an Object Muyavil Java Basics 3 April 11th, 2009 11:02 PM
referencing an object in an edit item template dan195 ASP.NET 1.0 and 1.1 Basics 3 September 25th, 2006 07:15 AM
Automation error The object invoked has disconnect vensee Crystal Reports 0 April 11th, 2005 06:12 PM
The object invoked has disconnected from its clien Ciarano Beginning VB 6 2 March 12th, 2004 11:38 AM
Referencing an object from within a procedure mike123abc Beginning VB 6 5 February 3rd, 2004 02:51 PM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.