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

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