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