Altova Authentic 2024 Desktop

Im unten gezeigten Codefragment (aus dem Beispiel AutomateAuthenticDesktop) wird gezeigt, wie man Fehler und COM-Ausgabeparameter behandelt. In der Methode AuthenticDesktop.ActiveDocument.IsValid(ref strErrorText, ref nErrorNumber, ref errorData) werden Ausgabeparameter verwendet, mit Hilfe derer im unten gezeigten Codefragment der Text einer Fehlermeldung generiert wird.

 

Das AutomateAuthenticDesktop Beispiel (siehe Datei form1.cs) befindet sich im Unterordner C# des Ordners API Examples:

 

 

Windows 7, Windows 8, Windows 10, Windows 11

C:\Benutzer\<Benutzername>\Dokumente\
Altova\Authentic\2024\%APPNAME%>Examples

 

Sie können das Projekt von Visual Studio 2012/2013/2015/2017/2019/2022 aus kompilieren und ausführen.

 

Codefragment

     

       // Handler for the "Validate" button

       private void validate_Click(object sender, EventArgs e)

       {

           // COM errors get returned to C# as exceptions. Use a try/catch block to handle them.

           try

           {

               // Method 'IsValid' is one of the few functions that use output parameters.

               // Use 'object' type for these parameters.

               object strErrorText = "";

               object nErrorNumber = 0;

               object errorData = null;

 

               if (!AuthenticDesktop.ActiveDocument.IsValid(ref strErrorText, ref nErrorNumber, ref errorData))

               {

                   // The COM call succeeds but the document is not valid.

                   // A detailed description of the problem is returned in strErrorText, nErrorNumber and errorData.

                   listBoxMessages.Items.Add("Document " + AuthenticDesktop.ActiveDocument.Name + " is not valid.");

                   listBoxMessages.Items.Add("\tErrorText  : " + strErrorText);

                   listBoxMessages.Items.Add("\tErrorNumber: " + nErrorNumber);

                   listBoxMessages.Items.Add("\tElement    : " + (errorData != null ? ((XMLSpyLib.XMLData)errorData).TextValue : "null"));

               }

               else

               {

                   // The COM call succeeds and the document is valid.

                   listBoxMessages.Items.Add("Document " + AuthenticDesktop.ActiveDocument.Name + " is valid.");

               }

           }

           catch (Exception ex)

           {

               // The COM call was not successful.

               // Probably no application instance has been started or no document is open.

               listBoxMessages.Items.Add("Error validating active document: " + ex.Message);

           }

       }

 

© 2017-2023 Altova GmbH