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

Extrange IF behavior

0 views
Skip to first unread message

Rubens Lara

unread,
Jul 12, 2000, 3:00:00 AM7/12/00
to
I am using the following code in my application. Using DELPHI 5.0 DEBUG and
evalueting the IF expression at the third line it returned TRUE. The
extrange behavior is that program execution jumped to the lines beyond //
OTHER INSTRUCTIONS comment line. It should have executed the instructions on
lines 5 and 6.

While not RWFP0012DM.RWFP0009RxQuery.eof do
begin
IF VarIsEmpty(RWFP0012DM.RWFP0009RxQueryQDOLER.AsString) then
begin
RWFP0012DM.RWFP0009RxQuery.Next;
Continue;
end;

// OTHER INSTRUCTIONS
// ....
end;

Can someone explain that?

Thanks in advance.

Rubens Lara
r...@ajato.com.br
Brazil

Dave Nottage

unread,
Jul 12, 2000, 3:00:00 AM7/12/00
to
"Rubens Lara" wrote:
<code snipped>

Ouch! Where did those names come from?

> Can someone explain that?

I did a similar loop in D5, and it worked as expected.

If there isnt a Next in the "other instructions", it'll end up as an endless
loop

Probably better to do:

While not RWFP0012DM.RWFP0009RxQuery.eof do
begin

IF not VarIsEmpty(RWFP0012DM.RWFP0009RxQueryQDOLER.AsString) then
begin
// OTHER INSTRUCTIONS
end;
RWFP0012DM.RWFP0009RxQuery.Next;
end;

--
Dave Nottage

Ed Dressel (Team DM)

unread,
Jul 12, 2000, 3:00:00 AM7/12/00
to
Occationally the debugger displays the wrong value :-<. If you have GExperts,
try their SendDebug in DBugIntf.pas unit. (If you don't have it, you may want to
try it). Otherwise, try adding RWF....AsString to a list box for you to view.

Ed Dressel


> I am using the following code in my application. Using DELPHI 5.0 DEBUG and
> evalueting the IF expression at the third line it returned TRUE. The
> extrange behavior is that program execution jumped to the lines beyond //
> OTHER INSTRUCTIONS comment line. It should have executed the instructions on
> lines 5 and 6.
>

> While not RWFP0012DM.RWFP0009RxQuery.eof do
> begin

Rubens Lara

unread,
Jul 12, 2000, 3:00:00 AM7/12/00
to
Hi Dave,

Thanks for your time.

You are right about "IF" construction. The "IF not" way you have wrote is
better.

But, the problem is that he program behaves like if the "IF" does not exist.
It allways jumps inside the "IF begin - end;" construction despite of the
logical "VarIsEmpty" expression result is TRUE or FALSE.

I have changed it the way you have suggested and it does not work properly
yet. See the following code:

while not RWFP0012DM.RWFP0009RxQuery.Eof do
begin
if not VarIsEmpty(RWFP0012DM.RWFP0009RxQueryQDOLER.AsString) then


begin
// OTHER INSTRUCTIONS
end;

end;
RWFP0012DM.RWFP0009RxQuery.next;

The "OTHER INSTRUCTIONS" inside the "IF begin - end;" construction is
allways executed despite of the logical "VarIsEmpty" expression result is
TRUE or FALSE.

It's hard to believe ! Can someone explain that?

Thanks again,

Rubens Lara
r...@ajato.com.br
Brazil

> I did a similar loop in D5, and it worked as expected.
>
> If there isnt a Next in the "other instructions", it'll end up as an
endless
> loop
>
> Probably better to do:
>

> While not RWFP0012DM.RWFP0009RxQuery.eof do
> begin

Brandon Lilly

unread,
Jul 12, 2000, 3:00:00 AM7/12/00
to
I have had trouble occasionally with the debugger displaying the wrong
values. Is it possible that the field value is NULL and not unassigned? We
usually have to check for both (VarIsEmpty & VarIsNull)

Also, I noticed you are using VarIsEmpty on a string... I would suspect
that to cause strange results, but then I am no expert on variants. I would
suggest changing .AsString to .Value and see what that does.


Brandon Lilly
--
Remove "no_spam" from address to email directly


"Rubens Lara" <rub...@rl-sistemas.com.br> wrote in message
news:8khs6j$u...@bornews.borland.com...

Mark Erbaugh

unread,
Jul 12, 2000, 3:00:00 AM7/12/00
to

Rubens Lara <rub...@rl-sistemas.com.br> wrote in message
news:8khlau$r...@bornews.borland.com...

> I am using the following code in my application. Using DELPHI 5.0 DEBUG
and
> evalueting the IF expression at the third line it returned TRUE. The
> extrange behavior is that program execution jumped to the lines beyond //
> OTHER INSTRUCTIONS comment line. It should have executed the instructions
on
> lines 5 and 6.
>
> While not RWFP0012DM.RWFP0009RxQuery.eof do
> begin
> IF VarIsEmpty(RWFP0012DM.RWFP0009RxQueryQDOLER.AsString) then
> begin
> RWFP0012DM.RWFP0009RxQuery.Next;
> Continue;
> end;
>
> // OTHER INSTRUCTIONS
> // ....
> end;
>
> Can someone explain that?
>
> Thanks in advance.
>

It seems like the action is correct. The CONTINUE statement caused the next
iteration of the WHILE to execute, so it should skip all the statements to
the end of the WHILE loop. Optimization of the WHILE loop may make it look
like it's skipping to the last statement in the WHILE loop. If the test in
the IF statement is true, the // OTHER INSTRUCTIONS should not be executed.

Mark

Rubens Lara

unread,
Jul 12, 2000, 3:00:00 AM7/12/00
to
Thanks,

It seems the DEBUG gave me wrong information.
The solution was:

IF Len(RWFP0012DM.RWFP0009RxQueryQDOLER.Value) > 0 then
....

Regards,

Rubens Lara

"Brandon Lilly" <nospam...@medevolve.com> escreveu na mensagem
news:396c77e9@dnews...


> I have had trouble occasionally with the debugger displaying the wrong
> values. Is it possible that the field value is NULL and not unassigned?
We
> usually have to check for both (VarIsEmpty & VarIsNull)
>
> Also, I noticed you are using VarIsEmpty on a string... I would suspect
> that to cause strange results, but then I am no expert on variants. I
would
> suggest changing .AsString to .Value and see what that does.
>
>
> Brandon Lilly
> --
> Remove "no_spam" from address to email directly
>
>

> "Rubens Lara" <rub...@rl-sistemas.com.br> wrote in message

> > > While not RWFP0012DM.RWFP0009RxQuery.eof do
> > > begin

Ping Kam

unread,
Jul 12, 2000, 3:00:00 AM7/12/00
to
Since RWFP0012DM.RWFP0009RxQueryQDOLER is a persistent field, why don't you
use the IsNull method?

While not RWFP0012DM.RWFP0009RxQuery.eof do
begin

IF Not (RWFP0012DM.RWFP0009RxQueryQDOLER.IsNull) then
begin
// OTHER INSTRUCTIONS
// ....
end;
RWFP0012DM.RWFP0009RxQuery.Next;
end;

HTH,
Ping

Rubens Lara <rub...@rl-sistemas.com.br> wrote in message

news:8kih2h$8p...@bornews.borland.com...

Rubens Lara

unread,
Jul 13, 2000, 3:00:00 AM7/13/00
to
Thanks Ping,

It really worked fine the way you have proposed.

"Ping Kam" <pk...@quikcard.com> escreveu na mensagem
news:8kj200$do...@bornews.borland.com...

0 new messages