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

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