The strong type checking provided by Delphi is useful for improving the correctness of the code, a topic I tend to stress in my introductory books. Strong type checking, though, can also be a nuisance, as you might rather have a procedure or a class that can act on different data types. This issue is addressed by a new feature of the Object Pascal language, recently added to similar languages like C# and Java, called generics. This is what I wrote in 1994 in a book about C++70:
Now you can declare a class without specifying the type of one or more data members: this operation can be delayed until an object of that class is actually declared. Similarly, you can define a function without specifying the type of one or more of its parameters until the function is called.
70 The book is "Borland C++ 4.0 Object-Oriented Programming", written by me with Steve Tendon, with a forward by Philippe Kahn.
Now, 14 years later, this feature is getting into Object Pascal. You can guess I'm somewhat excited to have generics (they are called templates in C++) in Delphi, although I have to say I have witnessed distinct overuse of this feature that I didn't fully understand at the time. I doubt generics will be overused in Delphi, quite the contrary: there is the risk that a very significant language upgrade gets almost unnoticed. This chapter will try to delve into the topic, showing you the value of generics in Delphi and how they can be applied even to standard visual programming.
Was this article helpful?
What you need to know about… Project Management Made Easy! Project management consists of more than just a large building project and can encompass small projects as well. No matter what the size of your project, you need to have some sort of project management. How you manage your project has everything to do with its outcome.