Solved

PBSYSTEM error - Null object reference

Posted on 2001-07-06
6
443 Views
Last Modified: 2013-12-26
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
0
Comment
Question by:sureshpodaralla
6 Comments
 
LVL 4

Expert Comment

by:Bhatti
ID: 6264511
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
 
LVL 1

Expert Comment

by:levr
ID: 6271384
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
 
LVL 3

Accepted Solution

by:
hink earned 50 total points
ID: 6285993
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:sureshpodaralla
ID: 6304963
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
 
LVL 3

Expert Comment

by:hink
ID: 6307383
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
 

Author Comment

by:sureshpodaralla
ID: 6308783
Hink, Thanks for ur comments.I hope ur suggestions
works for me.
Thanks,
suresh
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Update (December 2011): Since this article was published, the things have changed for good for Android native developers. The Sequoyah Project (http://www.eclipse.org/sequoyah/) automates most of the tasks discussed in this article. You can even fin…
Here is a helpful source code for C++ Builder programmers that allows you to manage and manipulate HTML content from C++ code, while also handling HTML events like onclick, onmouseover, ... Some objects defined and used in this source include: …
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now