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

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