Share via


createComponent 関数

同じパッケージ (.wsc ファイル) に含まれている別のスクリプト コンポーネントへの参照を返します。

value = createComponent(componentID)

  • componentID
    インスタンスを作成するスクリプト コンポーネントの一意の識別子を指定します。

解説

createComponent メソッドを呼び出すことにより、同じファイルにある別のスクリプト コンポーネントの機能を組み込むことができます。詳細については、「同じパッケージ内の別のスクリプト コンポーネントの参照」を参照してください。

次のコードは、同じパッケージ内にスクリプト コンポーネントが 2 つある例です。1 番目のスクリプト コンポーネントに定義されている math メソッドが呼び出されると、1 番目のスクリプト コンポーネントは 2 番目のスクリプト コンポーネントを呼び出します。

メモ   <script> 要素内のスクリプトを隠蔽するには、CDATA セクションが必要です。詳細については、「スクリプト コンポーネント ファイルと XML 適合性」を参照してください。

<package>
<component id="component1">
<registration progid="component.FrontEnd"/>
<public>
   <method name="math"/>
</public>
<script language="JScript">
<![CDATA[
function math(){
   return createComponent("component2")
}
]]>
</script>
</component>

<component id="component2">
<registration progid="component.Math"/>
<public>
   <method name="add"/>
</public>
<script language="JScript">
<![CDATA[
function add(n1, n2){
   return n1+n2;
}
]]>
</script>
</component>
</package>

このパッケージは、登録後、次のように使用できます。

set o1 = CreateObject("component.FrontEnd")
Set o2 = o1.math()
msgbox(o2.add(4,5))

参照

同じパッケージ内の別のスクリプト コンポーネントの参照