Link to home
Start Free TrialLog in
Avatar of sureshpodaralla
sureshpodaralla

asked on

PBSYSTEM error - Null object reference

I am using PB7.3 OLEObjects to access Panagon(a software)
objects.In some cases, when i request a reference to
an object, we recieve a NULL pointer stored in the
OLEObject. This typically happens when the object
we request(for what ever reason) doesn't exist,but i
i thought it did. The program tries to then call
methods of the returened object and PB generates
a NULL object reference error, and it goes directly
to the SystemError script. Result: The program crashes
and burns.
I came to know that we can trap errors while
accessing external objects by creating
 a new Standard class user object which is
inherited from oleobject. Using ExternalExceptionEvents
we can trap the errors.
I dont know how to use this techinique in my case.
I'd sure like to know if you can shed any light
on this topic.
Any help you could provide would be greatly
appreciated.

Sincerly Yours,
Suresh Podaralla
Avatar of Bhatti
Bhatti

Hallo Suresh,

I think at the moment when you call methods of the returned object the object is not referenced or created or befire destroyed. Please look this corner carefully.
This is a working code with OLE usage.
It shows how to check if OLE is created
before calling the OLE function.
The most possible is that creation of OLE failed.
Any questions - keep asking. Lev

// create OLE
integer li_rc
string ls_message
if IsValid(oleLtrCtrl) then // clean up
     li_rc = oleLtrCtrl.DisconnectObject()
     destroy      oleLtrCtrl
end if

oleLtrCtrl = create oleobject

li_rc = oleLtrCtrl.ConnectToNewObject("DLLName.OSXName")
CHOOSE CASE li_rc
     CASE -1
          ls_message = "Invalid Call: the argument is the Object property of a control"
     CASE -2
          ls_message = "Class name not found"
     CASE -3
          ls_message = "Object could not be created"
     CASE -4
          ls_message = "Could not connect to object"
     CASE -9
          ls_message = "Other error"
     CASE ELSE
          // Success
END CHOOSE

IF li_rc <> 0 THEN
     MessageBox("OLE Error", ls_message)
     return 0
END IF
// call OLE function
li_rc = oleLtrCtrl.my_function()
// check for function return
IF li_rc < 0 THEN
     MessageBox(...)
     return 0
END IF
ASKER CERTIFIED SOLUTION
Avatar of hink
hink
Flag of Czechia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of sureshpodaralla

ASKER

Thanks for your comments.
By the way i would like to ask one more question?
If i want to use a insertable component(external,
actually a scanner control,which allows the application
to scan the papers.It works fine with vb applications.But i dont know how to use it using Power Builder), i know
that i need to use OLE.I am able to insert the component.
But i dont know how to work with component methods.
Please suggest me a solution.

Thanks,
suresh
If You insert the control into Your window as "ole_1", then You can call its function directly:
ole_1.object.its_function(args....)

You can handle its events directly. You will see the list of its events by the standard way (rightclick -> Script ... -> Select event).

Attention:
Not all OCX's work fine with PB. Inserting OCX's into window causes creating binary data section in window. Sometimes PB crashes and the window is no more accessible by Window Painter. Be aware and make backups of Your library or object by working with it.

Hink, Thanks for ur comments.I hope ur suggestions
works for me.
Thanks,
suresh