Delphi Programming

  1. Home
  2. Computing & Technology
  3. Delphi Programming

New language features in Delphi for .Net

On classes and visibility of class members

By Zarko Gajic, About.com

First, Delphi for .Net classes can be marked as sealed. Sealed classes cannot be extended through inheritance - such a class can not be used as a base class for some other (derived) class.

Here's an example of a sealed class:

~~~~~~~~~~~~~~~~~~~~~~~~~
type
   TSealedClass = class sealed (TObject)
     public
       procedure SomeMethod;
   end;

   TCannotCompile = class(TSealedClass) ;
~~~~~~~~~~~~~~~~~~~~~~~~~

If you try to compile the above code, you'll get "Cannot extend sealed class TSealedClass", since TSealedClass is declared as sealed.

Second, as with the Win32 version of Delphi, any member of a class (variable, method, property, ...) has a visibility attribute. In addition to "standard" Delphi visibility specifiers, Delphi for .Net adds two new access specifiers. Again, when you start a new FCL Windows Forms application, and look in the code that defines the main Form, you'll see two new "groups": strict private and strict protected.

A member of a class declared with the strict private visibility is accessible only within the class in which it is declared - not visible to procedures or functions declared within the same unit.

A member of a class declared with the strict protected visibility is accessible within the class in which it is declared, and within any descendant class.

Here's an example:

~~~~~~~~~~~~~~~~~~~~~~~~~
type
   TWinForm = class(System.Windows.Forms.Form)
   strict private
     Components: System.ComponentModel.Container;
     DataGrid1: System.Windows.Forms.DataGrid;
     procedure InitializeComponent;
     procedure TWinForm_Load(sender: System.Object; e: System.EventArgs) ;
   strict protected
     procedure Dispose(Disposing: Boolean) ; override;
   public
     constructor Create;
   end;
~~~~~~~~~~~~~~~~~~~~~~~~~

Class methods, fields, properties

As in Delphi for Win32, methods can be declared with the keyword class. Class methods can be accesed without the need to first explicitly declare an object of a class. Beside class methods, Delphi for .Net also supports class fields and class properties.

Theory, theory,..

Uh, oh, ok. The truth is that there are so many new features in Delphi 8, if I was to write just a sentence about every I would need to write a smaller book.
I suppose we'll learn much more if we simply start developing projects for the .Net using Delphi 8 (and that's exactly what you should expect from the next article).

Until the next time ... if you have any comment or question be sure to post on the Delphi Programming Forum.

Forward to Part III: Should you call Free in the .Net Delphi world?

Explore Delphi Programming

More from About.com

Delphi Programming

  1. Home
  2. Computing & Technology
  3. Delphi Programming
  4. Learn Delphi for .NET
  5. New language features in Delphi for .Net

©2008 About.com, a part of The New York Times Company.

All rights reserved.