Chris:
Thanks! I had briefly thought about that, but no so absolutely little about
JScript I figured it would take too long to learn it well enough to get what
I needed. Your list below provides food for thought. However, I would
agree to be somewhat concerned about performance issues, and the fact that
JScript can't natively see VBScript functions/sub as you say makes it less
appealing.
As for performance, I've already decided we'll implement a caching system so
performance isn't an issue so much as fast implementation, maintainability,
robustness, and composability.
As for not needing events, you are thinking events to be like the are
commonly used i.e. OnClick, not have the can be used in all cases. For
example, let's assume you have a communications component; it might have an
"OnBytesReceived" event. In my case I've attached a script I wrote that
uses one event called PagePartClass. It lets someone define a simple
"PagePart" for our website (you can see this code live in action on our home
page at
http://www.xtras.net)
The PagePart is a class with properties like Name, Title, HeadClass,
ImageUrl, Text, etc. If "Text" is not empty, it displays the value in the
Text property. If Text IS empty, it concatonates the value in Name to
"_ShowText" and calls that Sub (i.e. Sub ppLeadingVendors_ShowText). And it
works GREAT.
The problems I was trying to solve was not in the example but in some much
more complex code where I have events like "_BeforeRecordAdd" and
"_AfterRecordAdd" that I only want to run if they exist. If they don't
exist, I don't want them to run, but if they do exist I want to run with w/o
ON ERROR RESUME NEXT in force. Further, I would like to be able to display
an error message prior to calling like the following
"MyModule_BeforeRecordAdd expected two parameters but none were passed." As
it, I get a cryptic error message that requires a lot of time to trace.
Of course if we switch to ASP.NET, I'll have none of these problems, just
not ready to do that yet. :-)
-Mike
"Chris Hohmann" <no****@thankyou.com> wrote in message
news:eu**************@TK2MSFTNGP12.phx.gbl...
Mike-
Have you considered looking to JScript to achieve some of the reflective
features your looking for.
IsFunction = typeof function
IsProperty = object.hasOwnProperty(proName)
IsMethod = Use object.hasOwnProperty AND typeof object.property
ParameterCount = function.length
Parameters = function.arguments
CallByName = JScript supports optional parameters
CallStack = function.caller
Global Namespace = intrinsic global object
I'm not recommending that you rewrite your existing code. However, you
could create JScript wrappers for your VBScript classes so you could
make use of the above. Also, you may consider creating a generic wrapper
for all VBScript classes. Since JScript allows you to enumerate objects,
you could pass in a VBScript class instance to the generic wrapper which
would dynamically "implement" the class. Here's a proof of concept on
enumerating a VBScript class instance.
<script language="VBScript" runat="SERVER">
Class foo
Public x
Function init()
x = 123
End Function
End Class
Dim f
Set f = New foo
f.init()
enumerate(f)
</script>
<script language="JScript" runat="SERVER">
function enumerate(obj){
var i;
for(i in obj){
Response.Write(i + ":" + (typeof obj[i]) + "<br>");
}
}
</script>
The typeof call will return "Unknown" for VBScript functions/subs since
it has no idea what a VBScript function is (nor should it). You could
replace the typeof call with the VBScript functions you've developed. I
was reluctant to send this reply since I am certain there are
considerable performance issues related to burdening ASP with this
additional abstraction layer. As such, dynamically implementing the
VBScript class is left as an exercise for the reader. :) I would
strongly suggest you rethink your class execution model. I remain
convinced that attempting to carrying over the VBA event/messaging model
to VBScript is inappropriate due to the stateless nature of the ASP. In
layman's terms, ASP should not be expected to handle OnClick. Could you
provide some more specifics on the class model? Perhaps someone here
could offer an alternative that avoids the above chaos.
HTH
-Chris Hohmann