Vote UpVote

Beware using anonymous methods in loops

TURBU Tech – Quick, what’s the output of this simple routine? procedure AnonLoop; var   i: integer;   proc: TProc;   ProcList: TList<TProc>; begin   ProcList := TList<TProc>.Create;   for i := 1 to 5 do     ProcList.Add(       procedure()       begin         write(i, ' ');       end);   for proc in ProcList do     proc;   procList.Free; end; Intuitively, you’d think it would write “1 2 3 4 5″, but you’d be wrong.  It ...
Favorite? Off-Topic? Mason Wheeler @ 2010-11-22 04:15


Visits: 771
Votes: 4
Favorites: 0
Off-Topic: 0

Visits by Source

User Actions

Users who voted for this posting

Alister Christie
Charles Ardour
Mohammed Nasman
Contact us to advertise on DelphiFeeds.com

Community Links

Torry Firebird News


Please login or register to use this functionality.
(click on this box to dismiss)