The Classes vs Object declaration (Views: 101)


99.9% (if not 100%) of the times we are using the Class declaration even when we do not need it.


First of all lets clear what are the diffrences between the two type of declaration.

Class declaration is actully like the TObject object. There isn't any diffrence between the 2 declarations:

  TMyClass1 = class

and the second declaration:

  TMyClass2 = class(TObject)
    {         ....... }

If you will notice in delphi (in Delphi 3 and above) when you press on CTRL+Space you will find in the first declaration the same functions like the second declaration.

And if you will look in the delphi help file, you will find that Class word created for components !!!!

If you will declare this:

  TMyObject = object
    { ....... }

You will not find any function or property inside of it, if you did not declare of it.
In the Delphi help file, they are writing that the Object declaration can not receave any properties.

TheObject reserve word is very good for OOP of functions, like let say a CODEC (Encryption and Decryption) of the same thing, we can build it in OOP without the need of a component or a memory allocations (although we can).

<< Back to main page