Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Isvalid() & Null object reference

880 views
Skip to first unread message

Tim Roberts

unread,
Nov 19, 1998, 3:00:00 AM11/19/98
to
Does anyone have any ideas why I sometimes get a null object reference
on the following line:

IF isvalid(object_a) AND isvalid(object_b) THEN
object_a.of_function(object_b)
END IF

Csaba Toth

unread,
Nov 20, 1998, 3:00:00 AM11/20/98
to trob...@bigfoot.com
Tim,

code something like this:

if ( isvalid(object_a) and not(isNull(object_a)) ) and (isvalid(object_b)
and not(isNull(object_b)) ) then
object_a.of_function(object_b)
end if

Regards

Csaba Toth

--
Csaba Toth
Programmer [Development]
cs...@addease.com.au

Addease Pty. Ltd.
P.O. Box 1484
COLLINGWOOD VIC 3066
Australia

Ph : +61 3 9416 2944
Fax: +61 3 9416 2580
web: http://www.addease.com.au

Timothy H. VanderWall

unread,
Nov 20, 1998, 3:00:00 AM11/20/98
to
Shouldn't the "not (IsNull...)" be coded BEFORE the "IsValid..."? I
believe it does the checks left to right. If so, you would still get a
null reference error.

-- Tim

Csaba Toth

unread,
Nov 23, 1998, 3:00:00 AM11/23/98
to Timothy H. VanderWall
Huh?

The logical condition is an AND man!
That means the entire condition has to be true in order for the test to evaluate
to true.
It makes no differece wich way PB evaluates anything. It could do it backwards!

The code works correctly, that is, you will NOT get a Null object reference!

Look up BOOL Algebra!!


Regards

Csaba Toth

Timothy H. VanderWall

unread,
Nov 23, 1998, 3:00:00 AM11/23/98
to
I know boolean algebra. It has been my experience (in over 30 years of
programming), however, that most current programming languages operate
in a linear fashion, and therefore must make one evaluation before the
other. In some implementations (maybe not Powerbuilder), checking for a
value before checking for a null will raise an exception condition.

Robert Martincic

unread,
Nov 23, 1998, 3:00:00 AM11/23/98
to
Powerbuilder doesn't use short-circuit Boolean evaluation so the order shouldn't
matter.

Robert

Craig Wagner

unread,
Nov 23, 1998, 3:00:00 AM11/23/98
to
Robert Martincic <rmar...@bju.edu> wrote:

On top of which, you shouldn't ever need to check an object reference variable
using IsNull ( ). The IsValid ( ) should be used to validate the existence of
objects.

---
Craig Wagner | E-mail: cwa...@metacorp.com
CPD Professional | Web: http://www.metacorp.com
Certified Powersoft Instructor | Phone: (503) 452-6343
Portland, OR USA |

Keeper of the PowerBuilder FAQ
http://www.teleport.com/~wagnerc/powerbuilder_faq.html

Csaba Toth

unread,
Nov 24, 1998, 3:00:00 AM11/24/98
to
I'm sorry, I'm lost for words.

Simon Caldwell

unread,
Nov 24, 1998, 3:00:00 AM11/24/98
to
Well it's true that

if IsValid(u_something) and u_something.uf_function() = TRUE.../

will fail if u_something is not valid (has not been created).
I suppose this is what Tim was getting at.

Simon

Csaba Toth wrote in message <3659EDD1...@addease.com.au>...

Tim Roberts

unread,
Nov 25, 1998, 3:00:00 AM11/25/98
to
Craig - IsValid() is failing in this case - I still get a null object
reference. I added the Isnull() - haven't seen the issue yet but it
usually takes a few days before the users manage to get it.

To the other Tim,
Whether there is a specific order in evaluation or not, doesn't really
matter - coding for the order is not good programming. You should
NEVER depend on the internal processes of the language - they can
change from version to version making your code version specific -
very bad for maintenance.

On Mon, 23 Nov 1998 17:47:59 GMT, cwa...@metacorp.com (Craig Wagner)
wrote:

>Robert Martincic <rmar...@bju.edu> wrote:
>
>On top of which, you shouldn't ever need to check an object reference variable
>using IsNull ( ). The IsValid ( ) should be used to validate the existence of
>objects.
>
>>Powerbuilder doesn't use short-circuit Boolean evaluation so the order shouldn't
>>matter.
>>
>>Robert
>>

Ken Heiman

unread,
Dec 3, 1998, 3:00:00 AM12/3/98
to
We had this problem some time ago. We made our own uf_IsValid function
that also returned False if IsValid returns NULL. The problem is that
the return from IsValid() is :

Boolean. Returns a boolean value indicating whether objectname has
been created. If objectname is NULL, IsValid returns NULL.

If IsValid() returns NULL, then it doesn't fail the if condition. You
need to check IsValid AND IsNull to ensure you're not going to get
null object references.

Ken


On Tue, 24 Nov 1998 10:22:08 -0000, "Simon Caldwell"
<simonATgetrealsystemsDOTcom> wrote:

>Well it's true that
>
>if IsValid(u_something) and u_something.uf_function() = TRUE.../
>
>will fail if u_something is not valid (has not been created).
>I suppose this is what Tim was getting at.
>
>Simon
>
>Csaba Toth wrote in message <3659EDD1...@addease.com.au>...
>>I'm sorry, I'm lost for words.
>>
>>

0 new messages