About the author
Delphi 8 introduces two new property access specifiers. They are, add and remove. These two property access specifiers allow Delphi to support the CLR's multicast events model.
NB: Add and remove can be used by itself, or with each other, but NOT in conjunction with read or write.
An add or remove property access specifier needs to be followed by either a field, or a method. If what follows is a method, then the method needs to have a parameter of the same type as that declared on the property itself.
In addition, the Delphi 8 language has been enhanced to allow Include and Exclude to add and remove event handlers from events. The usage of the assignment operator (:=) is not allowed. To add an event handler to an event, use Include. To remove an event handler from an event, use Exclude.
An example showing the usage of add and remove is given below.
program MulticastEvents; {$APPTYPE CONSOLE} uses Classes; type TSomeEvent = procedure; TSomeObject = class private FOnSome: TSomeEvent; public procedure DoSome; property OnSome: TSomeEvent add FOnSome remove FOnSome; end; procedure Some1; begin WriteLn('Hello world, I am Some1'); end; procedure Some2; begin WriteLn('Hello world, I am Some2'); end; procedure Some3; begin WriteLn('Hello world, I am Some3'); end; procedure TSomeObject.DoSome; begin if Assigned(FOnSome) then FOnSome; end; var SomeObj: TSomeObject; begin SomeObj := TSomeObject.Create; Include(SomeObj.OnSome, Some1); Include(SomeObj.OnSome, Some2); Include(SomeObj.OnSome, Some3); SomeObj.DoSome; WriteLn; WriteLn('Some2 will now be removed...'); WriteLn; Exclude(SomeObj.OnSome, Some2); SomeObj.DoSome; WriteLn('End of demonstration for add and remove property access specifiers'); ReadLn; end.
Learn why the map is cool in Go!
A method to design records so that they're allocated on a specific byte boundary, such as 16 bytes, 512 bytes, 4096 bytes, etc.
Learn the command line used to compile System.pas in Delphi
How to free more space on your home drive by redirecting the location for SDKs in RAD Studio