|
Version 1.0
Console demo of delegating an interface to a property in Delphi with the implements keyword. |
|||||||
|---|---|---|---|---|---|---|---|
|
A single-file Delphi console program showing how the implements keyword lets a host class delegate an interface to a property. The host claims IWorker without writing its methods; the work is done by whichever implementation the Worker property holds. The demo obtains IWorker from the host, runs it, then swaps in a second implementation at runtime to show the caller does not change. It also shows how the delegate is reference counted while the host, held in a class-typed variable, is freed explicitly. Open the program in Delphi as a console project, compile and run it. It prints one line from each worker, then waits for Enter. It needs no third-party components and builds with any modern Delphi version. The two implementations, TWorker_Impl and TRobot_Worker_Impl, share the same IWorker contract, so the host never knows which one it is holding. The article explains the rules the compiler enforces, how identity and reference counting behave, and when to use TAggregatedObject or TContainedObject instead. Read the article : Delegating an Interface to a Property in Delphi - the implements keyword Free to use and modify |
|||||||
|
These links expire in one hour. Refresh the screen to extend the time.
|
|||||||
|
| |||||||