I am new of Delphi. In the documentation of TStrem class, i read it is an abstract class. So i think the compiler goes in error when i try to create it with
stream := TStream.Create();
Why not?
I am new of Delphi. In the documentation of TStrem class, i read it is an abstract class. So i think the compiler goes in error when i try to create it with
stream := TStream.Create();
Why not?
Copyright © 2021 Jogjafile Inc.
The Delphi language doesn't really have any formal concept of abstract class.
It is true that you can define a class to be abstract:
But you can perfectly well instantiate this class. In fact
class abstractin Delphi is a feature used only by the long abandoned Delphi .net compiler.A more useful definition of an abstract class is one that contains
abstractmethods. If you attempt to instantiate such a class, then a compiler warning will be emitted. Those warnings can be promoted to errors by way of a compiler option, if you wish.When the documentation refers to
TStreamas being abstract it in fact means that it is "conceptually" abstract. In fact it does not even have anyabstractmethods, so by my definition above it is not abstract.I'm really not sure why
TStreamdoes not contain abstract methods. I would suggest that theGetSize,SetSize,Read,WriteandSeekshould really be declaredabstract. I suspect that if the class were being designed today then they would be declaredabstractand likely they are not for historical reasons.Instantiating
TStreamis a very common mistake made by programmers less experienced in the Delphi RTL. Once the mistake has been made a couple of times, the lesson is usually learnt. Unfortunately the system provides no easy way for this mistake to be flagged up. Each and every new programmer just has to learn the hard way.