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

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