Your full service technology partner! 
-Collapse +Expand
Search Delphi Group:

-Collapse +Expand Delphi To/From
-Collapse +Expand Delphi Store

Prestwood eMagazine

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

   ► KBProgrammingDelphi for W...OOP   Print This    All Groups  
  From the April 2010 Issue of Prestwood eMag
Delphi OOP:
Delphi Member Field
Posted 12 years ago on 12/25/2008
Delphi Code Snippet:
 A flashcard from our Delphi Flashcards Library
 A code snippet from our Delphi 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 Member Field

In Delphi, it is common to start all member fields with "F" as in FName and FAge. You can initialize the value of member fields too.

Delphi member fields do not support static data. The workaround is to use the hybrid nature of Delphi and use a unit variable (a variable declared in the implementation section of a unit) and then access the unit variable with a member property.

Delphi doesn't support setting a member field to read-only. However, you can accomplish the task with a strict private member field and a read-only property.

Syntax Example:
TCyborg = class(TObject)
  FSerialNumber: String='A100';
FCyborgName: String;
FCyborgAge: Integer=0;

  FSeriesID: Integer=100;

Static Data

The following is an example of how to create static data in Delphi using a  unit variable and a class function to get the value (you could also use a class procedure to set the value).

More Info

Code:  Delphi Class Members (Class)
Definition:  Member Field


Share a thought or comment...
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 = P125A1
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 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 #101759 Counter
Since 12/25/2008
Sales Website: Or visit our legacy sales site:

©1995-2020 Prestwood IT Solutions.   [Security & Privacy]