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