4
votes

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 ...
Statistics
|
Visits by Source |
User Actions |