[fpc-devel] Delphi anonymous methods
Boian Mitov
mitov at mitov.com
Mon Mar 4 06:13:14 CET 2013
What people don't usually realize is that an anonymous method indeed is
internally expanded to a full blown object of unique class, with member
variables and all. Indeed I use the anonymous methods to effectively declare
a new class and make instance of it right in place with only couple of lines
of code. In most cases anonymous methods effectively eliminate the need to
declare new class for certain purpose.
With best regards,
Boian Mitov
-------------------------------------------------------
Mitov Software
www.mitov.com
-------------------------------------------------------
-----Original Message-----
From: Boian Mitov
Sent: Sunday, March 03, 2013 9:06 PM
To: FPC developers' list
Subject: Re: [fpc-devel] Delphi anonymous methods
Here is another even simpler example:
AItem := GComponentEditorList.Find(
function( AItem : IComponentEditorItem ) : Boolean
begin
Result := ( AComponent is
AItem.GetInstance().ComponentClass );
end
);
In this case you will either need additional member class variable (It will
increase the memory usage), or you will need to declare a whole class just
to achieve what I do with one line of code :-) . Sweet! :-)
More information about the fpc-devel
mailing list