Book Image

Delphi Cookbook

By : Daniele Teti
Book Image

Delphi Cookbook

By: Daniele Teti

Overview of this book

Table of Contents (14 chapters)
Delphi Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Duck typing using RTTI


 

"When I see a bird that walks like a duck and swims like a duck and quacks like a duck, I call that bird a duck."

 
 --James Whitcomb Riley

Clear, isn't it? What may not be so clear is that this approach can be used also in computer programming. Yes, even without an actual duck!

Getting started

Referring to Duck typing, Wikipedia gives the following explanation (http://en.wikipedia.org/wiki/Duck_typing):

In computer programming with object-oriented programming languages, duck typing is a style of typing in which an object's methods and properties determine the valid semantics, rather than its inheritance from a particular class or implementation of an explicit interface.

How can all these concepts be used in everyday programming? This is the question that this recipe aims to answer.

Let's say that you have a form and you want to inform the user that something bad happened, changing all the colorable components to clRed. I don't know what the property Color means for any...