Re: Encapsulating Objects in Objects? by klenwell
klenwell
Thu Oct 18 12:57:21 PDT 2007
> If I understand your original question correctly, then yes, it
> can be done (in vbs) and I have done it. But I can't offer any
> suggestions because I don't know what _your_ version of vbScript
> is capable of.
The O'Reilly pocket reference I'm using says "Features Version 5.5" on
the cover. I'm building an .hta script for usage on XP.
I worked around my original problem by moving creation of the
encapsulated object to the main script, like so:
Dim oApp: Set oApp = new AppHandler
oApp.Load ' this imports the file for NetworkHandler among others
Set oApp.NetworkHandler = new NetworkHandler
Wasn't able to create NetworkHandler in the m_load_network_handler
method inside AppHandler called by the Load method above as I
originally wanted.
In any event, I'd be curious to see how you or anyone else is doing
it.
Thanks,
Tom
On Oct 18, 10:02 am, mr_unreliable
<kindlyReplyToNewsgr...@notmail.com> wrote:
> Klenwell, I am having trouble figuring out what language that is.
>
> The "Set oApp = new AppHandler" looks like j(ava)script, but then
> there are no semicolons and/or brackets.
>
> Perhaps it is some other language that I'm not familiar with.
> But if it's vbScript, then it must be some newer version of vbs
> that isn't available here.
>
> If I understand your original question correctly, then yes, it
> can be done (in vbs) and I have done it. But I can't offer any
> suggestions because I don't know what _your_ version of vbScript
> is capable of.
>
> cheers, jw
> ____________________________________________________________
>
> You got questions? WE GOT ANSWERS!!! ..(but,
> no guarantee the answers will be applicable to the questions)
>
> klenwell wrote:
> > I have an AppHandler class that I want to encapsulate other handler
> > classes (GuiHandler, WmiHandler, etc.) as public properties of the
> > object, so they can be used like this:
>
> > Set oApp = new AppHandler
> > oApp.NetworkHandler.PingIp sIp
>
> > AppHandler, when created, would dynamically load and create the
> > encapsulated objects.
>
> > The concept works fine when applied to something like the native
> > FileSystemObject:
>
> > Dim oApp: Set oApp = new AppHandler
> > If ( oApp.FileHandler.FileExists("network_handler.class.vbs") ) Then
> > MsgBox("It works!")
> > End If
>
> > where FileHandler above is a public variable set in the
> > Class_Initialize method:
>
> > Set FileHandler = CreateObject ("Scripting.FileSystemObject")
>
> > But in trying to extend this concept to my own classes, I'm running
> > into problems. The following works (add_module dynamically loads the
> > file using ExecuteGlobal):
>
> > Dim oApp: Set oApp = new AppHandler
> > oApp.add_module("network_handler.class.vbs")
> > Set oApp.NetworkHandler = new NetworkHandler
>
> > But if I try to internalize this within a public Load method that
> > calls this private method:
>
> > Private Sub m_load_network_handler
> > add_module(m_nh_path)
> > Set NetworkHandler = New NetworkHandler
> > NetworkHandler.debug = debug
> > NetworkHandler.print_d("NetworkHandler child object loaded")
> > End Sub
>
> > I get an error: "Class Not Defined: NetworkHandler". I've tried a few
> > workarounds, but nothing has succeeded yet and they tend to lead me
> > away from my original concept.
>
> > Can someone point out my error to me? Is there a scoping issue with
> > ExecuteGlobal being used inside a private method?
>
> > Thanks,
> > Tom