Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Debugger skip a line of code


This question is answered.


Permlink Replies: 18 - Last Post: Jun 4, 2014 7:42 PM Last Post By: Van Swofford
John Birch

Posts: 135
Registered: 8/23/02
Debugger skip a line of code  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 1, 2014 3:43 PM
I have page control component that I need to loop through all its controls, so I wrote this code

for i := 0 to pred(pagecontrol1.ActivePage.ComponentCount) do begin
 
    //more code here
 
end;


The problem Delphi does not execute the for loop and jump to the end of the procedure, I tried to set a break point but it simply ignored. I know I should do that using controlcount and controls[] but why Delphi skip that line when I use componentcount ? is it a silent AV ?

btw It is Delphi XE5 and the pagecontrol is a third party component, I tried with Delphi standard pagecontrol component but there was no problem, Delphi execute the line normally!!
Tom Brunberg

Posts: 329
Registered: 12/27/04
Re: Debugger skip a line of code
Helpful
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 1, 2014 4:58 PM   in response to: John Birch in response to: John Birch
John Birch wrote:

I have page control component that I need to loop through all its controls, so I wrote this code

for i := 0 to pred(pagecontrol1.ActivePage.ComponentCount) do begin
 
    //more code here
 
end;


The problem Delphi does not execute the for loop and jump to the end of the procedure, I tried to
set a break point but it simply ignored. I know I should do that using controlcount and
controls[] but why Delphi skip that line when I use componentcount ? is it a silent AV ?

The Components list and ComponentCount relates to owned objects. When you drop items from the
tool palette onto the page controle the form becomes the owner, not the page control. Thus the page
controls componentcount is zero, and the loop never runs.
The Controls list and ControlCount relates to objects parented by the page control, iow the child
controls of the page control. Thus, Controls will contain the objects you have placed on the page
control.

btw It is Delphi XE5 and the pagecontrol is a third party component, I tried with Delphi standard
pagecontrol component but there was no problem, Delphi execute the line normally!!

Hmmm, so if you put a breakpoint on the preceding line and hover over the ComponentCount, what
number does it show with the 3rd party pagecontrol and with the Delphi one?
When you have built (for debugging), do you see a blue pill beside that line in both cases?
Can't explain better without seeing the actual code.


--
Tom Brunberg
firstname.lastname@welho.com

John Birch

Posts: 135
Registered: 8/23/02
Re: Debugger skip a line of code  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 1, 2014 5:20 PM   in response to: Tom Brunberg in response to: Tom Brunberg
Thanks Tom,

The problem is Delphi skip the for loop completely like it is not there, if I set a break point in a line above it and then check componentcount I see it has 0, same thing for the standard pagecontrol

And yes I see the blue pill in all cases and check mark when I run to indicate valid break point. There is nothing special in the code, I tried many different statements and found componentcount is the only one cause this, If you have by chance devexpress you can see this problem.
Tom Brunberg

Posts: 329
Registered: 12/27/04
Re: Debugger skip a line of code [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 2, 2014 12:16 AM   in response to: John Birch in response to: John Birch
John Birch wrote:

Thanks Tom,

The problem is Delphi skip the for loop completely like it is not there, if I set a break point
in a line above it and then check componentcount I see it has 0, same thing for the standard
pagecontrol

And yes I see the blue pill in all cases and check mark when I run to indicate valid break point.
There is nothing special in the code, I tried many different statements and found componentcount
is the only one cause this, If you have by chance devexpress you can see this problem.

Wow, that's a mystery.
Next step would be to look at the disassembly in CPU view, to see why it steps over the code. But I
don't have devexpress, and since using components/componencount is anyway wrong, it is not really
feasible for me to even install the trial. Of curiosity, it would be nice to know, though, I admit.

Regards

--
Tom Brunberg
firstname.lastname@welho.com
Adem Meda

Posts: 495
Registered: 12/28/98
Re: Debugger skip a line of code  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 3, 2014 1:27 AM   in response to: John Birch in response to: John Birch
John Birch wrote:

for i := 0 to pred(pagecontrol1.ActivePage.ComponentCount) do begin
 
    //more code here
 
end;

I'd try adding a few extra local variables for debug purposes.

Such as, one for 'ActivePage' and for 'ActivePage.ComponentCount' (or
ActivePage.ControlCount).

And, see if they indeed have the values that you expect.
John Birch

Posts: 135
Registered: 8/23/02
Re: Debugger skip a line of code  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 3, 2014 5:04 PM   in response to: John Birch in response to: John Birch
Yes out of curiosity I want to know why, here is the CPU instructions

 
000000000197D05A E8113CF7FE       call TcxPageControl.GetActivePage
000000000197D05F 4889C1           mov rcx,rax
000000000197D062 E8F905BCFE       call TComponent.GetComponentCount
000000000197D067 4833DB           xor rbx,rbx
000000000197D06A 8BF0             mov esi,eax
000000000197D06C 83EE01           sub esi,$01
000000000197D06F 7105             jno TMyfrm.btn1Click + $96
000000000197D071 E86AF9A8FE       call @IntOver
000000000197D076 3BDE             cmp ebx,esi
000000000197D078 0F8FC5000000     jnle TMyfrm.btn1Click + $163
000000000197D07E 83C601           add esi,$01


I found that all the lines get executed until address 197D078 , the execution jump to nop that I think the procedure end of the btn1 on click event.

 
000000000197D143 90               nop


What this mean ?
John Birch

Posts: 135
Registered: 8/23/02
Re: Debugger skip a line of code  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 4, 2014 11:26 AM   in response to: John Birch in response to: John Birch
After some search tried again now without using the "pred" function like this

 
for i := 0 to pagecontrol1.ActivePage.ComponentCount do begin
 
    //more code here
 
end;


And I found the for loop get executed and debugger step on it as normal, now I wrote it like this

 
for i := 0 to pagecontrol1.ActivePage.ComponentCount -1 do begin
 
    //more code here
 
end;


Problem is back, I think it is a Delphi bug related to integers but I dont know how to describe a bug like this.
Van Swofford

Posts: 397
Registered: 6/28/03
Re: Debugger skip a line of code  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 4, 2014 11:47 AM   in response to: John Birch in response to: John Birch
John Birch wrote:

After some search tried again now without using the "pred" function
like this

 
for i := 0 to pagecontrol1.ActivePage.ComponentCount do begin
 
    //more code here
 
end;


And I found the for loop get executed and debugger step on it as
normal, now I wrote it like this

 
for i := 0 to pagecontrol1.ActivePage.ComponentCount -1 do begin
 
    //more code here
 
end;


Problem is back, I think it is a Delphi bug related to integers but I
dont know how to describe a bug like this.

Does it work properly if you take the calculation out of the for
statement, like so:

temp := pagecontrol1.ActivePage.ComponentCount - 1;
for i := 0 to temp do begin
...
end;


--
Cheers,
Van

"Good judgment comes from experience, and a lot of that comes from bad
judgment." - Will Rogers
John Birch

Posts: 135
Registered: 8/23/02
Re: Debugger skip a line of code  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 4, 2014 12:03 PM   in response to: Van Swofford in response to: Van Swofford
Does it work properly if you take the calculation out of the for

No, for loop does not get executed.
Van Swofford

Posts: 397
Registered: 6/28/03
Re: Debugger skip a line of code  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 4, 2014 7:40 PM   in response to: John Birch in response to: John Birch
John Birch wrote:

Does it work properly if you take the calculation out of the for

No, for loop does not get executed.

Hmm. Does ComponentCount = 1? That's the only obvious thing that
would cause the loop to not execute.

--
Cheers,
Van

"Good judgment comes from experience, and a lot of that comes from bad
judgment." - Will Rogers
Van Swofford

Posts: 397
Registered: 6/28/03
Re: Debugger skip a line of code  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 4, 2014 7:42 PM   in response to: Van Swofford in response to: Van Swofford
Van Swofford wrote:

John Birch wrote:

Does it work properly if you take the calculation out of the for

No, for loop does not get executed.

Hmm. Does ComponentCount = 1? That's the only obvious thing that
would cause the loop to not execute.

Ah, never mind. I just read the rest of the thread.

--
Cheers,
Van

"Good judgment comes from experience, and a lot of that comes from bad
judgment." - Will Rogers
karl pritchett

Posts: 15
Registered: 1/6/09
Re: Debugger skip a line of code  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 4, 2014 11:59 AM   in response to: John Birch in response to: John Birch
John Birch wrote:
After some search tried again now without using the "pred" function like this

 
for i := 0 to pagecontrol1.ActivePage.ComponentCount do begin
 
    //more code here
 
end;


And I found the for loop get executed and debugger step on it as normal, now I wrote it like this

 
for i := 0 to pagecontrol1.ActivePage.ComponentCount -1 do begin
 
    //more code here
 
end;


Problem is back, I think it is a Delphi bug related to integers but I dont know how to describe a bug like this.

You said " if I set a break point in a line above it and then check componentcount I see it has 0"
So you're doing for i:= 0 to -1 do ...........
And the code is being skipped because the start count is greater than the exit count
That's normal behavior in a for loop
What do you expect it to do?
John Birch

Posts: 135
Registered: 8/23/02
Re: Debugger skip a line of code  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 4, 2014 12:06 PM   in response to: karl pritchett in response to: karl pritchett
You said " if I set a break point in a line above it and then check componentcount I see it has 0"
So you're doing for i:= 0 to -1 do ...........
And the code is being skipped because the start count is greater than the exit count
That's normal behavior in a for loop
What do you expect it to do?

The debugger does not step on the for loop line.
Adem Meda

Posts: 495
Registered: 12/28/98
Re: Debugger skip a line of code  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 4, 2014 12:05 PM   in response to: John Birch in response to: John Birch
John Birch wrote:

  for i := 0 to pagecontrol1.ActivePage.ComponentCount do begin
    //more code here
  end;


This is wrong to begin with.

It should be:

  for i := 0 to (pagecontrol1.ActivePage.ComponentCount - 1) do begin
    //more code here
  end;

But, that's not all.

Why do you insist one using 'ComponentCount'?

Why not follow Tom's suggestion and use 'ControlCount'?

i.e.

  for i := 0 to (pagecontrol1.ActivePage.ControlCount - 1) do begin
    //more code here
  end;


Please do that and see if it works.
John Birch

Posts: 135
Registered: 8/23/02
Re: Debugger skip a line of code  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 4, 2014 12:08 PM   in response to: Adem Meda in response to: Adem Meda
Why do you insist one using 'ComponentCount'?

Why not follow Tom's suggestion and use 'ControlCount'?

You are not following me, I know that I should use ControlCount and said that already but I am just curious why debugger does not step on the line if I used ComponentCount.
karl pritchett

Posts: 15
Registered: 1/6/09
Re: Debugger skip a line of code
Correct
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 4, 2014 12:18 PM   in response to: John Birch in response to: John Birch
John Birch wrote:
Why do you insist one using 'ComponentCount'?

Why not follow Tom's suggestion and use 'ControlCount'?

You are not following me, I know that I should use ControlCount and said that already but I am just curious why debugger does not step on the line if I used ComponentCount.

The debugger doesn't stop on that code because it isn't executed
0 > -1 so the for loop isn't executed at all
John Birch

Posts: 135
Registered: 8/23/02
Re: Debugger skip a line of code  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 4, 2014 12:24 PM   in response to: karl pritchett in response to: karl pritchett
The debugger doesn't stop on that code because it isn't executed
0 > -1 so the for loop isn't executed at all

Many thanks karl
Adem Meda

Posts: 495
Registered: 12/28/98
Re: Debugger skip a line of code  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 4, 2014 1:01 PM   in response to: John Birch in response to: John Birch
John Birch wrote:

Why do you insist one using 'ComponentCount'?

Why not follow Tom's suggestion and use 'ControlCount'?

You are not following me, I know that I should use ControlCount and said that
already but I am just curious why debugger does not step on the line if I
used ComponentCount.

I am following you; what I don't understand is why you're taking so much time
with it.

You could have saved yourself a lot of time by stopping the thing just before
(or at) the for-loop and pressed Ctrl+F7.

Then, when you write/type "pagecontrol1.ActivePage.ComponentCount" (without the
quotes) and pressed ENTER, you'd see that it has a value of ZERO.

Little wonder, then, the for-loop never gets executed.
John Birch

Posts: 135
Registered: 8/23/02
Re: Debugger skip a line of code  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 4, 2014 3:15 PM   in response to: Adem Meda in response to: Adem Meda
You could have saved yourself a lot of time by stopping the thing just before
(or at) the for-loop and pressed Ctrl+F7.

Then, when you write/type "pagecontrol1.ActivePage.ComponentCount" (without the
quotes) and pressed ENTER, you'd see that it has a value of ZERO.

Little wonder, then, the for-loop never gets executed.

yes I was just expected different behavior.
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02