|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| ||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Can WSC components share code?
Is it possible to have code that can be shared between components within a WSC? Something like this for example;
Code:
<package>
<component id='a'>
<public>
<property name="p"><get/></property>
</public>
<script language="VBScript">
<![CDATA[
Function get_p()
get_p = Hello()
End Function
]]>
</script>
</component>
<component id='b'>
<public>
<property name="p"><get/></property>
</public>
<script language="VBScript">
<![CDATA[
Function get_p()
get_p = Hello()
End Function
]]>
</script>
</component>
Function Hello()
Hello = "Hello world"
End Function
</package>
Wrapping up the "Sub Hello()" code as a component would make it public. What I want the ability to share code between components within the package without making the shared code public. Is that possible? Regards. |
|
#2
|
||||||
|
||||||
|
Quote:
vb Code:
Introducing Custom Objects with WSC Creating a Custom Object with WSC Coding a Custom Object with WSC
__________________
Scripting problems? Windows questions? Ask the Windows Guru! Stay up to date with all of my latest content. Follow me on Twitter! Help us help you! Post your exact error message with these easy tips! Last edited by Nilpo : August 15th, 2009 at 04:16 AM. |
|
#3
|
|||
|
|||
|
Thanks Nilpo.
How do I reference the second component from the first one without making its properties public? Say Component A uses Component B like this; Code:
<?xml version="1.0"?>
<package>
<component id="A">
<public>
<property name="P"><get/></property>
</public>
<script language="VBScript">
<![CDATA[
Option Explicit
Function get_P()
Dim objB
Set objB = CreateComponent("B")
get_P = "Hello " & objB.P
End Function
]]>
</script>
</component>
<component id="B">
<public>
<property name="P"><get/></property>
</public>
<script language="VBScript">
<![CDATA[
Option Explicit
Function get_P()
get_P = "world"
End Function
]]>
</script>
</component>
</package>
Calling code: Code:
<%
Dim strWscPath, objA
strWscPath = Server.MapPath("main.wsc")
Set objA = GetObject("script:" & strWscPath & "#A")
Response.Write(objA.P)
Set objA = Nothing
%>
Result: "Hello world". But I can't get component A to use component B without making component B public. Do you know if it is possible? Thanks. |
|
#4
|
||||
|
||||
|
To my knowledge this isn't possible. A component cannot see a method in another component unless it's exposed publicly. That's the nature of having a self contained object.
You can, however, have private methods within a single component. |
|
#5
|
|||
|
|||
|
Thanks for the info Nilpo
|
![]() |
| Viewing: ASP Free Forums > System Administration > Windows Scripting > Can WSC components share code? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|