0
Votes
Undo
  1. Ashutosh Varshney
  2. PowerBuilder
  3. Wednesday, 13 December 2017 16:03 PM

Hello,

I have a custom ocx control on a PB classic window which interacts with MS Office. Right now, if the ocx file has not been deployed or registered, the application simply crashes after displaying "Error calling external object function' error. 

I want to be able check if the ocx is setup or not and let users continue to use my application but disable functions provided by that ocx. Any ideas how that can be done?

Thanks.

Accepted Answer
Michael Kramer Accepted Answer Pending Moderation
  1. Wednesday, 13 December 2017 17:34 PM
  2. PowerBuilder
  3. # Permalink
0
Votes
Undo

One solution is to use TRY-CATCH exception handling.

You can provide a user-friendly error message and disable functionality that requires the OCX.

Comment
Thanks Mike. But I already have it in a Try...Catch construct:



// Init op



Try



   ole_1.Object.Init ()   // This statement generates Error calling external object function message



Catch (Exception e)



   MessageBox ('Error', 'Init op failed.' )



End Try

  1. Ashutosh Varshney
  2. Wednesday, 13 December 2017 19:50 PM
Hi Ashutosh, Unfortunately your code catches the wrong type of exception.





Exception is the base class for checked exceptions

RuntimeError is the base class for unchecked exceptions





I would expect that the exceptions thrown by your call to Init( ) are either RuntimeError or OLERuntimeError (subclass of RuntimeError).



 



Try this:





TRY

OLE_1.Object.Init()

CATCH (RuntimeError exRuntime)

  MessageBox('Error', exRuntime.GetMessage( ))

END TRY





 



OLE Automation usually throws OLERuntimeError exceptions that include additional information. Therefore, I often wrap each block of OLE Automation calls with below code to enrich the error message exposed to callers that may only catch the exception as RuntimeError.





TRY

// ... OLE Automation calls ...



CATCH (OLERuntimeError exOLE)

  // Enrich error message

  exOLE.SetMessage(exOLE.Description + '~r~n' + exOLE.GetMessage( ))

  // Re-throw to expose enriched exception to caller

  THROW exOLE

END TRY



  1. Michael Kramer
  2. Thursday, 14 December 2017 09:44 AM
That works. Thanks Mike!

  1. Ashutosh Varshney
  2. Thursday, 14 December 2017 14:22 PM
There are no comments made yet.
Shenn Sellers Accepted Answer Pending Moderation
  1. Wednesday, 13 December 2017 20:06 PM
  2. PowerBuilder
  3. # 1
0
Votes
Undo

Does the OCX create any Registry entries?  I use Outlook Redemption and check the Registry to see if it is installed.  If I don't find it, I disable the features that use it.  All registered COM class objects are listed under HKEY_LOCAL_MACHINE\SOFTWARE\Classes\CLSID\.

Comment
Thanks Shenn. I was able to catch it using RuntimeError exception.

  1. Ashutosh Varshney
  2. Thursday, 14 December 2017 14:24 PM
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.