Given that an interface cannot implement any methods is there an alternative to achieve the equivelant? e.g. color all components yellow on entry and green when exited.
You can have all your components implement the same interface. And that interface could have a method to select the color.
You still have to iterate all your component dropped on a container (form, panel,...) when the event to change the color occur. Since all components implements the same interface, it can be called.
If you want existing components to implement that interface, you must derive you own component from the standard one and implement the interface.
Could be a lot of work. Not worth the effort IMO.
-
I suppose what I really want is to implement methods within the interface and don't understand why you can't. Example I gave was a trivial one but I can think of non trivial uses. – Tony Wolff Mar 4 at 16:41
-
An interface has no implementation. It is... an interface. A class can implement any interface the developer likes. Would be useful if you edit your question and show in a simple example the code you would like to use but you don't know how to write. – fpiette Mar 4 at 16:55
-
2@TonyWolff I see in your profile that you know Java. Delphi has no equivalent of Java's default methods. – Olivier Mar 4 at 17:08
-
That clarifies things, so any reason why delphi doesn't have default methods? – Tony Wolff Mar 4 at 17:18
-
class
? – AmigoJack Mar 4 at 16:06interface
? Otherwise, you can use RTTI instead. – Remy Lebeau Mar 4 at 17:10Color
property is declared in TControl class from which many VCL components are derived from. But sinceColor
property is declared in protected section of TControl class you can't interact with it directly through TControl type. – SilverWarior Mar 4 at 17:11