_XDocument2.Extension 属性

定义

获取一个对全局脚本对象的引用,该对象公开表单的主要表单代码文件中所包含的函数和全局变量。

public:
 property System::Object ^ Extension { System::Object ^ get(); };
public object Extension { get; }
member this.Extension : obj
Public ReadOnly Property Extension As Object

属性值

实现

示例

在以下示例中, Extension 属性通过 ObjectWrapper 接口用于调用名为 的 MyMethod自定义方法。 这是在托管代码中使用 Extension 属性所必需的:

ObjectWrapper o = (ObjectWrapper)thisApplication.XDocuments[0].<span class="label">Extension</span>;
 o.GetType().InvokeMember("MyMethod",
 BindingFlags.InvokeMethod |
 BindingFlags.DeclaredOnly | 
 BindingFlags.Public |  
 BindingFlags.Instance, null, o, null);

在以下示例中,可以使用 Extension 属性从自定义任务窗格访问名为 myCustomMethod InfoPath 项目类的方法:

//Custom method added to the project
public string myCustomMethod()
{
return "Method value";
}

若要从自定义任务窗格进行访问myCustomMethod,请使用 DHTML 窗口对象的 DHTML 外部属性:

objXDocument = window.external.XDocument;
myString = objXDocument.<span class="label">Extension</span>.myCustomMethod();

在以下示例中, Extension 属性通过 ObjectWrapper 接口用于调用名为 的 MyMethod自定义方法。 这是在托管代码中使用 Extension 属性所必需的:

ObjectWrapper o = (ObjectWrapper)thisApplication.XDocuments[0].<span class="label">Extension</span>;
 o.GetType().InvokeMember("MyMethod",
 BindingFlags.InvokeMethod |
 BindingFlags.DeclaredOnly | 
 BindingFlags.Public |  
 BindingFlags.Instance, null, o, null);

在以下示例中,可以使用 Extension 属性从自定义任务窗格访问名为 myCustomMethod InfoPath 项目类的方法:

//Custom method added to the project
public string myCustomMethod()
{
return "Method value";
}

若要从自定义任务窗格进行访问myCustomMethod,请使用 DHTML 窗口对象的 DHTML 外部属性:

objXDocument = window.external.XDocument;
myString = objXDocument.<span class="label">Extension</span>.myCustomMethod();

注解

Extension 对象便于使用在 InfoPath 表单的脚本文件中实现的函数和全局变量。 通常,可以从自定义任务窗格、自定义对话框,或者在需要直接访问函数和变量的视图的 XSL 转换 (XSLT) 中使用该对象。

若要在自定义任务窗格中使用 Extension,必须先使用 DHTML window 对象的动态 HTML (DHTML) external 属性,设置一个对 XDocument 对象的引用:

objXDocument = window.external.XDocument;

重要提示:此成员只能由与当前打开的窗体在同一域中运行的表单访问,或者由已授予跨域权限的表单访问。

适用于