Creating a Custom Object with WSC - Wrapping up the wizard
(Page 4 of 4 )
In step five of the component wizard you’re given an opportunity to add events to your component. The ZipFolder component does not have any events, so I simply skipped that step and moved on to the last one, where you’re asked to confirm your actions. Pressing Finish on this screen will output a WSC file to the directory you specified in the first step.
<?xml version="1.0" ?>
The first line defines the document type as an XML file. This will cause the XML parser to validate your WSC file before it is loaded by the script host. You can omit this line if you choose, but I recommend leaving it in place. Future releases may not be so relaxed about improperly formatted XML files.
<package>
<component id="ZipFolder">
<?component error="false" debug="false" ?>
<registration
progid="ZipFolder.WSC"
classid="{22b7a277-1736-4889-801c-8f240fdf1f3a}"
description="ZipFolder"
remotable="no"
version="1.00">
</registration>
The entire WSC file is wrapped inside of an optional <package> element. If your WSC file contains more than one component, you should leave this element in place.
Next, a <component> element identifies and encapsulates your component. The name is irrelevant in most cases as it’s only used internally when more than one component is provided. It’s good practice to provide an id nonetheless.
You should recognize the information in the <registration> section. Its attributes contain the information you provided in the first step of the wizard, including the description, ProgID, and version number for your component. All of these items are optional, but you’ll need to provide at minimum a ClassID if you intend to register your component. It’s a good idea to provide a friendly ProgID as well, otherwise you’ll have to remember that ClassID!
<public>
<property name="FullName">
<get/>
<put/>
</property>
<property name="Path">
<get/>
</property>
<property name="Count">
<get/>
</property>
<property name="Name">
<get/>
</property>
<method name="Open">
<parameter name="strFile"/>
</method>
<method name="Create">
<parameter name="strFile"/>
</method>
<method name="Add">
<parameter name="strFile"/>
<parameter name="blnKeepOriginal"/>
</method>
<method name="AddMultiple">
<parameter name="varSource"/>
<parameter name="blnKeepOriginal"/>
</method>
<method name="Extract">
<parameter name="strFolder"/>
</method>
</public>
The <public> element defines your object’s public interface. These are the properties and methods that you want to be available when using your object in other scripts. Only those properties and methods listed here will be exposed through your object.
<script language="VBScript">
<![CDATA[
]]>
</script>
</component>
</package>
Finally, the <script> element provides a place for you to put your object’s code. It’s good practice to specify the language attribute, but the scripting engine is generally smart enough to figure it out if you do not. You can add as many <script> elements as you like, so you’re not limited to a single language! You can also mix and match any compatible languages.
I’m out of space once again. In my next article we’ll finish creating our own custom object. I'll show you the code required for the ZipFolder object, teach you some extras features you can use in your own components, and show you how to protect the source code in your components if you choose to distribute them. Until next time, keep coding!
You can download a working example of this component here.
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |