Mirror

The Classes vs Object declaration (Views: 101)


Problem/Question/Abstract:

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

Answer:

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:

type
  TMyClass1 = class
    {.......}
  end;

and the second declaration:

type
  TMyClass2 = class(TObject)
    {         ....... }
  end;

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:

type
  TMyObject = object
    { ....... }
  end;

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