Declares a property.
<property name="propertyName" [internalName="propertyVariable"] />
or
<property name="propertyName"> <get [internalName="getFunctionName"] /> <put [internalName="putFunctionName"] /> </property>
Tip In XML, you can implement elements that have no content (such as the <property> element) by closing the element with />.
Properties can be exposed as simple values. In that case, the property is treated as a global variable inside the script component file.
You can also implement properties as procedures (functions or subroutines), which allows you to calculate a property value and to control whether a property is read-only, read-write, or write-only. In this technique, properties are implemented as a procedure (function or subroutine) in a separate <script> element. The <property> element maps the name of the property to the procedures used to implement it. The names of the procedures must match the internal names you specified in the <property> element.
When putFunctionName is called, it is passed one argument that contains the value to which to set the property.
In addition to the standard syntax shown above, you can use a shorthand notation to specify information what would otherwise be added using child tags. For example, if you want to declare a property with a "get" and "put" accessor of the same name as the property, you can use the following syntax:
<property name="myproperty" get put/>
which is functionally equivalent to:
<property name="myproperty">
<get/> <put/></property>
If you wanted to explicitly name those accessors differently from the default, you can use the following syntax:
<property name="myproperty" get="testget" put="testput"/>
To specify a default property, include the attribute dispid="0" in the <property> element. For details, see Exposing Properties.
The following script component fragment shows the definition for four properties (sname, age, dateOfBirth, and mstatus). The sname property is a simple value. The age property is read-only, and is implemented with the function readAge. The dateOfBirth property is read-write, and is implemented wih the functions readDOB and writeDOB. Finally, the mstatus property is implemented with the default functions get_mstatus and put_mstatus.
Note A CDATA section is required to make the script in the <script> element opaque. For details, see Script Component Files and XML Conformance.
<public> <property name="sname"/> <property name="age"> <get internalName="readAge"/> </property> <property name="dateOfBirth"> <get internalName="readDOB"/> <put internalName="writeDOB"/> </property> <property name="mstatus"> <get/> <put/> </property> </public> <script language="VBScript"> <![CDATA[ Dim sname ' Read-write sname property (no functions). Dim gDOB ' Global variable used to store date of birth. Dim gMStatus ' global variable used to store marital status. Function readDOB() ' Gets value of dateOfBirth property. readDOB = gDOB End Function Function writeDOB(newDOB) ' Sets value of dateOfBirth property. If isDate(gDOB) Then ' Error checking. gDOB = newDOB End If End Function Function readAge() ' Calculates read-only age property. If isDate(gDOB) Then dobM = DatePart("m", gDOB) dobD = DatePart("d", gDOB) dobY = DatePart("yyyy", gDOB) todayY = DatePart("yyyy", Date) age = todayY - dobY ' Adjust if birthday has not yet occurred this year. bday = DateValue(dobM & "/" & dobD & "/" & todayY) If DateDiff("d", bday, DateValue(Date)) < 0 Then age = age - 1 End If readAge = age End If End Function Function get_mstatus() ' Reads value of mstatus property. get_mstatus = gMStatus End Function Function put_mstatus(s) ' Writes value of mstatus property. If s = "M" Or s = "S" Then gMStatus = s Else gMStatus = "?" End If End Function ]]> </script>
<event> Element | <method> Element | Exposing Events | Exposing Methods | Exposing Properties