Log On
Embarcadero Home
Watch, Follow, &
Connect with Us
Share This
QualityCentral
Communities
Articles
Blogs
Resources
Downloads
Help
QualityCentral
Delphi-BCB
Compiler
Delphi
Anonymous Methods
BASM
Code Generation/Optimization
Error Recovery
Errors - Warnings
Exceptions
Execution
Finalization
Generics
Header Generation
Interaction with UI
Interfaces
Language
Linker
Make Logic
Memory Manager
OBJ Generation
OBJ Support
Other Compiler
Packages
RTTI
String Resources
TD Debug Info
Thread Local Storage
Version resilience
You are not logged in.
Help
Print
Public Report
Report From:
Delphi-BCB/Compiler/Delphi/Anonymous Methods
[ Add a report in this area ]
Report #:
103383
Status:
Open
Anonymous methods can use for-loop counters without a warning - wierd debugging
Project:
Delphi
Build #:
16.0.4358.45540
Version:
16.3
Submitted By:
Andreas Hausladen
Report Type:
Minor failure / Design problem
Date Reported:
2/13/2012 10:02:09 AM
Severity:
Infrequently encountered problem
Last Updated:
3/20/2012 2:24:39 AM
Platform:
All platforms
Internal Tracking #:
289930
Resolution:
None
(Resolution Comments)
Resolved in Build:
:
None
Duplicate of:
None
Voting and Rating
Overall Rating:
No Ratings Yet
0.00 out of 5
Total Votes:
None
Description
An anonymous method can capture a for-loop counter what makes the counter a non-local variable (this usually isn't allowed). As a result the debugger jumps out of the loop and back into the loop with every iteration. The CPU View shows the source line "end;" of the method in the "loop" code.
Non-local variables aren't allowed to be used as a for-loop counter. (X1019) But anonymous methods circumvents this compiler rule.
I also saw that the compiler generated an "Int16 range check" for a Int32 loop counter instead of an overflow check if the counter was captured. But I wasn't able to reproduce this is in a simple example.
EAX contains an Int32 and not a Int16, but the compiler generated
005107E8 0500800000 add eax,$00008000
005107ED 3DFFFF0000 cmp eax,$0000ffff
005107F2 7605 jbe $005107f9
005107F4 E87345EFFF call @BoundErr
005107F9 050080FFFF add eax,$ffff8000
Steps to Reproduce:
1. Create a new Console Application
2. Replace the code with the following program
3. Set a breakpoint on the for-loop
4. Start and step over [F8] the loop for some time
Expected:
The current debugged line is within the loop
Actual:
The debugger jumps the the methods "end" and back into the loop.
program QC103383;
{$APPTYPE CONSOLE}
uses
SysUtils;
procedure Test;
var
I: Integer;
P: TProc;
begin
for I := 0 to 10 do // breakpoint here, step over
Write; // step over
I := 0;
P :=
procedure
begin
Inc(I);
end;
P;
end; // why are we here, while we are in the for-loop?
begin
Test;
end.
Workarounds
None
Attachment
None
Comments
None
View Your Reports
Search
Server Response from: ETNACODE01
Developer Tools
Blackfish SQL
C++Builder
Delphi
FireMonkey
Prism
InterBase
JBuilder
J Optimizer
HTML5 Builder
3rdRail & TurboRuby
Database Tools
Change Manager
DBArtisan
DB Optimizer
ER/Studio
Performance Center
Rapid SQL
Technical Articles
Tutorials
White Papers
Press Releases
Newsletters
Add Content (GetPublished)
Audio
Audio & Video
Video
Bugs & Suggestions (QualityCentral)
Discussion Forums
Examples (CodeCentral)
Tags
Technology Partners
Downloads
Free Trials
Registered User Downloads
Beta Programs
Add Content (GetPublished)
Articles
Blogs
Bugs & Suggestions (QualityCentral)
Discussion Forums
Examples (CodeCentral)
Member Services
About
Connect with Us