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

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