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

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