T
Tappy Tibbons
I do not know exactly how to explain what I am asking for, but here goes...
Say I have a simple set of classes:
=========
Public Class clsPerson
Public FirstName As String
Public LastName As String
Public BillingAddress As clsAddress
Public ShippingAddress As clsAddress
End Class
Public Class clsAddress
Public AddressLine1 As String
Public AddressLine2 As String
Public City As String
Public StateCode As String
Public ZipCode As String
End Class
==========
From my calling form, I want to do something like:
Public Function DoTest()
Dim oPerson As New clsPerson()
oPerson.FirstName = "John"
oPerson.LastName = "Smith"
oPerson.BillingAddress.AddressLine1 = "12345 E 6th St"
...'do some other stuff
...
End Function
In clsPerson, I could just define "Public BillingAddress As NEW clsAddress",
but I do not always have a billing address. If I do not have one, I do not
want to create an instance of that class. This class is going to be used by
the XML serializer class, and long story short, is that I do not want the
class initialized of there is not going to be any real data in it.
Is there a way to automatically create/set that class to a NEW instance of
itself the first time it is accessed at runtime?
Is there a way I could use an error handler from within the class to trap
the "Object reference not set to an instance of an object." error, then
figure out which class member was responsible for raising the error, then
set that class member to a NEW instance of itself and then continue?
Are there other ways to do this?
Thanks!
Say I have a simple set of classes:
=========
Public Class clsPerson
Public FirstName As String
Public LastName As String
Public BillingAddress As clsAddress
Public ShippingAddress As clsAddress
End Class
Public Class clsAddress
Public AddressLine1 As String
Public AddressLine2 As String
Public City As String
Public StateCode As String
Public ZipCode As String
End Class
==========
From my calling form, I want to do something like:
Public Function DoTest()
Dim oPerson As New clsPerson()
oPerson.FirstName = "John"
oPerson.LastName = "Smith"
oPerson.BillingAddress.AddressLine1 = "12345 E 6th St"
...'do some other stuff
...
End Function
In clsPerson, I could just define "Public BillingAddress As NEW clsAddress",
but I do not always have a billing address. If I do not have one, I do not
want to create an instance of that class. This class is going to be used by
the XML serializer class, and long story short, is that I do not want the
class initialized of there is not going to be any real data in it.
Is there a way to automatically create/set that class to a NEW instance of
itself the first time it is accessed at runtime?
Is there a way I could use an error handler from within the class to trap
the "Object reference not set to an instance of an object." error, then
figure out which class member was responsible for raising the error, then
set that class member to a NEW instance of itself and then continue?
Are there other ways to do this?
Thanks!