Tech Articles


How to capture error messages from an ActiveX control


Normally when you use OLEObject to connect to an ActiveX control and encounter an error, you will get the generic run time error ‘R0035 – Application terminated. Error calling external object function xxx’.

 

I have run across a very simple way to capture the actual error code and message generated by the ActiveX control.

 

First, create a new Standard Class object and select oleobject for the type.

 

Next add the following instance variables:

 

ULong ErrorCode

String ErrorText

 

Then add this code to the externalexception event:

 

ErrorCode = ResultCode

ErrorText = Description

 

Finally save the object as n_oleobject.

 

In your script that calls the ActiveX control functions you will do the following:

 

n_OLEObject oleTheObj

Integer li_rc

 

oleTheObj = Create n_OLEObject

li_rc = oleTheObj.ConnectToNewObject(“TheObject.Name”)

If li_rc = 0 Then

   try

      oleTheObj.TheFunction()

   catch ( RuntimeError rte )

      PopulateError(oleTheObj.ErrorCode, oleTheObj.ErrorText)

      MessageBox(“OLE Runtime Error #” + &

            String(Error.Number), Error.Text, StopSign!)

      oleTheObj.DisconnectObject()

      Return

   end try

   oleTheObj.DisconnectObject()

Else

   MessageBox(“OLE Connect Error #” + String(li_rc), &

         “Connect To Object Failed!”, StopSign!)

End If

 

You’ll notice that in the catch section I used PopulateError to get the instance variables with the error information. I did this so I would also have the objectname/scriptname/linenumber for error logging if this were a real application.

Comments (0)
There are no comments posted here yet

Find Articles by Tag

JSON .NET Std Framework Oracle Menu Expression Stored Procedure Error ODBC Database Connection Windows OS OLE UI Modernization Sort DataType Debugging Text Event Handling TortoiseGit Automated Testing .NET DataStore Graph Data Migration Charts CrypterObject Git RichTextEdit Control SQL Server Android PowerBuilder PowerScript (PS) Export Validation CI/CD Export JSON Encoding Testing MessageBox Resize License OAuth Azure WinAPI PostgreSQL Mobile IDE TLS/SSL Windows 10 Icons Database Table Debug Event Handler Array Elevate Conference Open Source 64-bit Jenkins Variable SqlModelMapper Model Import JSON Source Code RibbonBar Builder Web Service Proxy Database Profile SQL Import PBDOM Branch & Merge PFC Filter Trial Linux OS TreeView iOS UI Repository NativePDF Window DevOps DragDrop OrcaScript Authorization UI Themes DLL SVN File Application PDF ActiveX CoderObject TFS COM Encryption Event XML Deployment Web API Installation DataWindow External Functions .NET Assembly API HTTPClient PowerBuilder Compiler JSONGenerator Interface Outlook JSONParser Configuration Service PowerServer Mobile RibbonBar PostgreSQL ODBC driver Authentication Platform SnapObjects SOAP Messagging Source Control RESTClient Excel Database Table Data SnapDevelop PowerBuilder (Appeon) Icon 32-bit Database Table Schema Script PowerServer Web Bug WebBrowser Syntax C# SqlExecutor GhostScript DataWindow JSON Design Database Object Debugger SDK REST Performance BLOB Class InfoMaker PDFlib Database OAuth 2.0 Database Painter Transaction