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

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