Class Properties NET

Class properties can be accessed without an object reference. Class property accessors must themselves be declared as class static methods, or class fields. A class property cannot be published, and cannot have stored or default value definitions.

You can introduce a block of class static properties within a class declaration by using the class var block declaration. All properties declared after class var have static storage attributes. A class var block is terminated by the following:

  1. Another class var declaration
  2. A procedure or function (i.e. method) declaration (including class procedures and class functions)
  3. A property declaration (including class properties)
  4. A constructor or destructor declaration
  5. A visibility scope specifier (public, private, protected, published, strict private, and strict protected) For example:

type

TMyClass = class strict private class var // Note fields must be declared as class fields

FRed: Integer; FGreen: Integer; FBlue: Integer; public class var // Introduce a block of class properties property Red: Integer read FRed write FRed;

Green: Integer read FGreen write FGreen;

Blue: Integer read FBlue write FBlue;

procedure Proci; // Ends the class var block.

end;

You can access the above class properites with the code:

  1. Red := 0;
  2. Blue := 0; TMyClass.Green := 0;
Project Management Made Easy

Project Management Made Easy

What you need to know about… Project Management Made Easy! Project management consists of more than just a large building project and can encompass small projects as well. No matter what the size of your project, you need to have some sort of project management. How you manage your project has everything to do with its outcome.

Get My Free Ebook


Post a comment