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
sureshpodarallaAsked:
Who is Participating?
 
hinkConnect With a Mentor Commented:
This will not prevent the application object (dllname.ocxname) to close itself and then will be nullobject referenced again.

But You can call function "setautomationpointer" anywhere. If the application is not running yet, it returns -1. In addition, returned object can be your user defined class inherited from oleobject. Example:

oleobject ole1
my_oleobject ole2

ole1.connecttonewobject(class_identifier)

----------------------------------
ole1.app_function() // this command is able to generate runtime error,
even if connecttonewobject was successfull
----------------------------------
My solution:

if ole1.setautomationpointer(ole2)<0 then goto app_invalid
ole2.app_function()

/*
In addition, runtime errors generated by app_function
can be treated in ole2 error script
*/
0
 
BhattiCommented:
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.
0
 
levrCommented:
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
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
sureshpodarallaAuthor Commented:
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
0
 
hinkCommented:
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.

0
 
sureshpodarallaAuthor Commented:
Hink, Thanks for ur comments.I hope ur suggestions
works for me.
Thanks,
suresh
0
All Courses

From novice to tech pro — start learning today.