So it appears you are creating a VBScript object, and trying to store
it in the current ASP session, for use in later page hits. I can see
at least one problem with this approach.
You have to remember that ASP is using a scripting engine instance to
process your VBScript code. Once ASP has finished processing your
code for that page hit, it is free to release the scriping engine
instance that processed your VBScript code. So any VBScript objects
you created using that scripting engine instance will at that point
be invalid. Sure, there may be a variant stuffed into the
Dictionary, probably with a variant subtype like VT_DISPATCH, but
that variant would no longer contain a valid reference to your
VBScript object. So while you might be able to pull a "non-null"
object out of the Dictionary, what you get back is effectively
useless.
Your alternatives are either to use a "real" object not implemented
by a scripting engine (ideally a free-threaded object, not apartment
threaded), or stuff the values of the fields of the class
into the session (as mentioned in a previous post).
-Jimmy Hutson
--- In padnug@xxxxxxxxxxxxxxx, "Perry Pederson" <perandtim@xxxx>
wrote:
>
> I've stumbled onto an asp problem at work where I'm cleaning up a
ton
> of code, and needed to store some ASP 'class' data types (a user
> defined type consisting of variant variables) in a
ASP "dictionary",
> which serves as a "collection" container.
>
> All was going well until I found out that I needed to persist the
> contents of the collection container across a ASP page reload. I
> stored the collection into the Session object and can restore it
from
> the Session object without problems. The (restored) container
shows
> that it has the "original" keys and number of "class" data types
> stored in the container, but when I attempt to access a "member" of
> the class data type, I get a "Object does not support this method
or
> property" error. Since I can't do a cast in ASP, I'm not sure how
to
> restore the class objects, unless I hack a form of serialization
into
> the code.
>
> In case it's difficult to follow my description, here's a simple
> version of what I'm doing:
>
> (ASP, not ASP.NET):
>
> class person
> dim nAge
> end class
>
> dim Jane
>
> Jane = new person
> Jane.nAge = 42
>
> dim objCollection
> set objCollection = Server.CreateObject("Scripting.Dictionary")
>
> objCollection.Add "Person1", Jane
>
> ' Example: Jane can be restored out of the collection:
>
> dim aPerson
>
> set aPerson = objCollection.Item("Person1")
>
> Response.Write aPerson.nAge
>
> ' 42 is printed out-- proof that Jane's data can be obtained out of
> the collection.
>
> Session("Preserved_Dictionary") = objCollection ' store the
collection
>
> [ ASP page reloads; objCollection is disposed. Attempt to restore
> the info stored in the Session object ]
>
> dim newCollection
>
> set newCollection = Session("Preserved_Dictionary")
>
> Response.Write newCollection.Count
>
> ' 1 is printed; the new collection contains one object
>
> ' Additional proof that the newCollection contains info:
>
> dim svar
> dim keys
>
> svar = gdictSVAInfo.Items
> keys = gdictSVAInfo.Keys
>
> for i = 0 to newCollection.Count-1
>
> Response.Write "#" & i & " k: " & keys(i) & ": "
>
> if isnull(svar(i)) then
> Response.Write "null"
> else
> Response.Write "not null"
> end if
>
> Response.Write "<br>"
>
> next
>
> ' output is "#0 k: Person1: not null"
>
> ' Cool! The object exists, the key (Person1) was restored, let's
use
> it!
>
> dim failedObj
>
> set failedObj = newCollection.Item("Person1")
>
> ' A check on failedObj shows that it is not null-- it is set to an
> object.
>
> Response.Write failedObj.age
>
> ' Boom! A "Object does not support this method or property" error
> occurs here. "FailedObj" appears not to be "cast" as a type.
>
>
> Attempts to cast to a "class" type don't work, as all variables in
> ASP are variants and only base type converstions (CStr, CBool,
etc.)
> are supported.
>
> Any help on this rather odd case would be very much welcome!
>
> Thanks for reading,
>
> Perry
------------------------ Yahoo! Groups Sponsor --------------------~-->
$4.98 domain names from Yahoo!. Register anything.
http://us.click.yahoo.com/Q7_YsB/neXJAA/yQLSAA/dpFolB/TM
--------------------------------------------------------------------~->
|