I.T. Discussion Community!
-Collapse +Expand
Search Prism Group:

-Collapse +Expand Prism To/From
-Collapse +Expand Prism Study Test
-Collapse +Expand Prism Store

Prestwood eMagazine

April Edition
Subscribe now! It's Free!
Enter your email:

   ► KBProgrammingDelphi PrismOOP   Print This     
  From the November 2015 Issue of Prestwood eMag
Prism OOP:
Delphi Prism Member Field
Posted 11 years ago on 12/25/2008 and updated 9/4/2009
Prism Code Snippet:
 A flashcard from our Prism Flashcards Library
 A code snippet from our Prism Code Snippets Page


General Info: Member Field

Also known as a Class Field.

A class variable defined with a specific class visibility, usually private visibility. A member property is different than a member field. A member property uses a member field to store values through accessor methods (getters and setters). For example, it is common to use a private member field to store the current value of a property. The current values of all the class member fields is the current state of the object.

Languages Focus: Member Field

What modifiers apply to member fields, if any? Typical member field modifiers include scope modifiers (private, protected, etc.) and read-only. Can you initialize the value of a member field when declared ensuring a default value?

Delphi Prism Member Field

In Prism you can set the visibility of a member field to any visibility: private, protected, public, assembly and protected or assembly or protected.

Prism supports the readonly modifier for member fields which is handy for constant like data. In this case, I chose not to preface my read-only member field with "F" so it's usage is just like a read-only property.

Prism also support the class modifier (static data) for member fields.

Delphi developers should notice the use of := to initialize a member field (in Delphi you use an =).

Syntax Example:

Cyborg = class(System.Object)


FSerialNumber: String:="A100";


FCyborgName: String;

FCyborgAge: Integer:=0;

class SeriesID: Integer:=100; readonly;


A Simple Example

The following example uses our class above. Notice for the static member, you can use either an instance reference (a variable), or the type name (the class name. That's why static members are sometimes referred to as class members. Static members belong to the class and you can reference by the class name.

Note: In Prism, you can refer to static members using an instance or class type. In VB.Net you get a warning and in C# you get a compiler error. My preferred usage is to stick with the class type (the class name).

namespace CR_StaticMembers;
/// Summary description for MainForm.

MainForm = partial class(System.Windows.Forms.Form)
method button1_Click(sender: System.Object; e: System.EventArgs);
method Dispose(disposing: Boolean); override;
  Cyborg = class(System.Object)
FSerialNumber: String:="A100";
FCyborgName: String;
FCyborgAge: Integer:=0;
    class SeriesID: Integer:=100; readonly;
{$REGION Construction and Disposition}
constructor MainForm;
// Required for Windows Form Designer support
// TODO: Add any constructor code after InitializeComponent call
method MainForm.Dispose(disposing: Boolean);
if disposing then begin
if assigned(components) then
// TODO: Add custom disposition code here
  inherited Dispose(disposing);
method MainForm.button1_Click(sender: System.Object; e: System.EventArgs);
//Read static member field BEFORE we create our object.
//Notice the use of the class name, not an object name.
MessageBox.Show("We will now build a series " + Cyborg.SeriesID + " robot.");
  var MyRobot := New Cyborg;
  MyRobot.FCyborgName := "John";
MyRobot.FCyborgAge := 34;
  MessageBox.Show("We created a " + MyRobot.FCyborgAge + " year old robot named " + MyRobot.FCyborgName + ".");
  //You can refer to static members using an instance.
//(in VB.Net you get a warning, in C# you get a compiler error).
MessageBox.Show("A series " + MyRobot.SeriesID + " robot.");
  //However, my preferred usage is to stick with the class name.
MessageBox.Show("A series " + Cyborg.SeriesID + " robot.");


Note: The public member fields FCyborgName and FCyborgAge are used here for demonstration only. You normally want to make them private and access them via a member property. Also note that SeriesID starts with an uppercase "S" instead of the customary "F" because SeriesID behaves similar to a read-only properity.

More Info

Definition:  Member Field


Share a thought or comment...
Comment 1 of 1

I believe in the .Net world they want member fields to start with a lower case letter.  So I would name it fSeriesID rather than FSeriesID.  Properties on the other hand they say to start with an upper case letter.

Posted 10 years ago
Write a Comment...
Sign in...

If you are a member, Sign In. Or, you can Create a Free account now.

Anonymous Post (text-only, no HTML):

Enter your name and security key.

Your Name:
Security key = P1244A1
Enter key:
Code Contributed By Mike Prestwood:

Mike Prestwood is a drummer, an author, and creator of the PrestwoodBoards online community. He is the President & CEO of Prestwood IT Solutions. Prestwood IT provides Coding, Website, and Computer Tech services. Mike has authored 6 computer books and over 1,200 articles. As a drummer, he maintains play-drums.com and has authored 3 drum books. If you have a project you wish to discuss with Mike, you can send him a private message through his PrestwoodBoards home page or call him 9AM to 4PM PST at 916-726-5675 x205.

Visit Profile

 KB Article #101760 Counter
Since 12/25/2008
Follow PrestwoodBoards on: 

©1995-2019 PrestwoodBoards  [Security & Privacy]
Professional IT Services: Coding | Websites | Computer Tech