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

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