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

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