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

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