Class members

VFP Object Oriented Programming model offered you Methods and Properties as members of classes. Those are always available in the .NET Compiler and now new class members:

  • Delegates. Think as function pointers.
  • Events. Included for Compatibility with other .NET Languages.
  • Fields. Are like properties, but they are now wrapped by methods like properties, instead they are accessed directly as in C structs.

Delegates and events

These are like the .NET counterparts but are different from the VFP model. A delegate is basically something you could invoke using this syntax:

oSomeObject.SomeDelegate(eSomeParameter)

You can think of a delegate like an object oriented version of the FunctionPointer you may know from other languages as C.

A delegate is declared inside a class as follows:

DEFINE CLASS SomeClass

DELEGATE SomeDelegate AS SomeType
TPARAMETERS aParam, bParam

ENDDEFINE

Note that there is no body inside the delegate, this is because as stated a delegate is some kind of construct you invoke. It could point to other methods as long the methods have a signature compatible (parameter and return type compatible) with the delegate.

One use of the delegates is to define the signature of events. Continuing from the sample above:

DEFINE CLASS SomeClass

DELEGATE SomeDelegate AS SomeType
TPARAMETERS aParam, bParam
EVENT SomeEvent as SomeDelegate

ENDDEFINE

Fields

A field is like a property except that is accessed directly. Properties are always accessed thru methods (_Access and _Assign) whether you declare the method nor not.

Fields are declared in a similar way to properties

DEFINE CLASS MyClass
@MyField as string = "" ENDDEFINE

That is you declare a field by putting a @ before the field name. You can later create accessor for the field using other name as MyProperty_Access and MyProperty_Assign.

You can't have a Property with the same name of a field.

Static Members

In addition to the ability to create instance members. Now you can also define some members to be bound not to a specific object instance instead those methods are bound to a Class. Such members are useful to share an object / value between different object instances, instead of resorting to global variables and methods, breaking so encapsulation.

Static members are declared by writing the word static before the member declaration..

TestClass::MyStaticProperty = 24
TestClass::MyStaticMethod("test")


DEFINE CLASS TestClass
@MyField as string = ""

static MyStaticProperty as integer

static PROCEDURE MyStaticMethod
LPARAMETERS teValue
THISCLASS::MyStaticProperty += 1

ENDDEFINE

As you can see there is not need to create an object intance of TestClass to access the static properties and methods of TestClass.

Inside your class methods you can access your static members by using the following syntax:

.code0 { font-size: small; font-family: Consolas, "Courier New", Courier, Monospace; color: #000000; background-color: #ffffff;margin: 0em; } .code1 { color: #000000; } .code2 { color: #00008b; }

  THISCLASS::MyStaticProperty += 1
OR
  THISCLASS::MyStaticMethod(eValue)