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

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