The Equals virtual function is a placeholder for checking if two objects have the same logical value, a different operation than checking if two variables refer to the same object, something you can achieve with the = sign. However, and this is really confusing, the default implementation does exactly that:
function TObject.Equals(Obj: TObject): Boolean; begi n
There are some cases in the VCL source code in which the Equals call is indeed used as a replacement of the = test. The opposite approach is used, for example, by TStrings.Equals, in which the class compares the number of strings and the actual strings one by one.
The only section of the library in which this technique is significantly used (and probably the reason it was added) is the generics support, in particular in the Generics.Default and Generics.Collections units. However, defining an object equivalence mechanism "by value" is common in many Delphi libraries and frameworks, and having a standard way of doing this is certainly a big advantage.
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.