I just started to play with the new unit in Delphi 2010 IOUtils.pas
, and I found they put all the methods inside Records(TFile, TPath, TDirectory)
as class functions and procedure.
Is there any benefits of doing that inside records instead of classes? In both cases there's no need for any variables or instance, but I'm not sure if there any real benefits regarding memory consuming or performance improvement.
Class methods in records are used to group different methods into a common namespace. Thus you can have similar named methods for different purposes. For an example in IOUtils.pas look at the Exists function available in TFile and in TDirectory. The older approach was to have distinct function names for FileExists and DirectoryExists (which the implementations actually call).
While class methods inside classes can be used in the same way, they can in addition have another goal: they can be virtual. Called from a class variable this can lead to different implementations depending on the current content of that variable. This is not possible for records. As a consequence class methods in records are always static.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With