共用方式為


DataDOMEvent.ReportError 方法

建立 ErrorObject 物件,並將它新增至 ErrorsCollection 集合。

**命名空間:**Microsoft.Office.Interop.InfoPath
**組件:**Microsoft.Office.Interop.InfoPath (於 microsoft.office.interop.infopath.dll 中)

語法

'宣告
<DispIdAttribute(8)> _
Function ReportError ( _
    <InAttribute> varNode As Object, _
    <InAttribute> bstrShortErrorMessage As String, _
    <InAttribute> fSiteIndependent As Boolean, _
    <InAttribute> <OptionalAttribute> Optional bstrDetailedErrorMessage As String = "", _
    <InAttribute> <OptionalAttribute> Optional lErrorCode As Integer = 0, _
    <InAttribute> <OptionalAttribute> Optional bstrType As String = "modeless" _
) As ErrorObject
'用途
Dim instance As DataDOMEvent
Dim varNode As Object
Dim bstrShortErrorMessage As String
Dim fSiteIndependent As Boolean
Dim bstrDetailedErrorMessage As String
Dim lErrorCode As Integer
Dim bstrType As String
Dim returnValue As ErrorObject

returnValue = instance.ReportError(varNode, bstrShortErrorMessage, fSiteIndependent, bstrDetailedErrorMessage, lErrorCode, bstrType)
[DispIdAttribute(8)] 
ErrorObject ReportError (
    [InAttribute] Object varNode,
    [InAttribute] string bstrShortErrorMessage,
    [InAttribute] bool fSiteIndependent,
    [OptionalAttribute] [InAttribute] string bstrDetailedErrorMessage,
    [OptionalAttribute] [InAttribute] int lErrorCode,
    [OptionalAttribute] [InAttribute] string bstrType
)

參數

  • varNode
    與錯誤關聯的 XML 文件物件模型 (DOM) 節點。
  • bstrShortErrorMessage
    用於簡短錯誤訊息的文字。
  • fSiteIndependent
    設定 Error 物件的自動刪除條件。若為 true,則將在任何符合 XPath 運算式 (對應於 Error 物件) 的節點發生變更時刪除 Error 物件;若為 false,則將在指定事件物件的 Site 屬性傳回的節點發生變更時,刪除 Error 物件。
  • bstrDetailedErrorMessage
    用於詳細錯誤訊息的文字。
  • lErrorCode
    做為錯誤碼的數字。
  • bstrType
    預設值為 "modeless"。判斷是否會自動拒絕值的變更,或是否提示使用者接受或拒絕變更。另一個值為 "modal"。

傳回值

代表新建立的 ErrorErrorObject 物件。

備註

呼叫 ReportError 方法時,Microsoft Office InfoPath 2003 會建立 Error 物件,並將它新增至 Errors 集合中。當驗證條件約束無效時,會從集合移除錯誤。在某些案例中,可以使用 DeleteDeleteAll 方法明確地移除它們。

也可以使用 Add 方法建立錯誤。

注意

當您想要錯誤套用到相同類型的所有 XML DOM 節點時,應使用獨立於網站的錯誤。如果想要錯誤套用到特定的 XML DOM 節點,請使用依存於網站的錯誤。

注意

OnValidate 事件期間,只能使用 ReportError 方法。

範例

在下列範例中,使用 DataDOMEventObject 物件的 Site 屬性檢查節點的值。如果資料驗證失敗,則會使用 ReportError 方法建立自訂錯誤:

public void field1_OnValidate(DataDOMEvent e)
{
 if (int.Parse(e.Site.text) > 50)
 {
  e.ReportError(
   e.Site, 
   "Invalid quantity. The total number of each type of block cannot exceed 50.", 
   false,
   "",
   2,
   "modeless");
 }

 if (int.Parse(e.Site.text) < 0)
 {
  e.ReportError(
   e.Site, 
   "Invalid quantity. The total number of each type of block cannot be less than 0.", 
   false,
   "",
   2,
   "modeless");
 }
}

請參閱

參考

DataDOMEvent 介面
DataDOMEvent 成員
Microsoft.Office.Interop.InfoPath 命名空間