PrestwoodBoards.com
-Collapse +Expand

Prism

Search Prism Group:

Advanced
-Collapse +Expand Prism Group Home
-Collapse +Expand Message Board
-Collapse +Expand Knowledge Base
-Collapse +Expand Prism To/From
To/FromCODEGuides
-Collapse +Expand Prism Study Test
PRESTWOODCERTIFIED
-Collapse +Expand Prism Store
PRESTWOODSTORE
-Collapse +Expand Members Only
Prestwood Tip Jar
Tip Jar
Finding something useful?

Add to the
Tip Jar!

Prestwood eMagazine

Subscribe now!
Enter your email:


   PrestwoodBoardsKBProgrammingDelphi PrismOOP   
Go To Random Article
  From the July 2010 Issue of Prestwood eMag
 
Prism OOP:
Delphi Prism Member Property (property..read..write)
By Mike Prestwood
12/20/2008, Last updated 7/9/2010
 
Prism Code Snippet:
 A flashcard from our Prism Flashcards Library
 A code snippet from our Prism Code Snippets Page


Delphi Prism Member Property

Like Delphi, Delphi Prism uses a special property keyword to both get and set the values of properties. The read and write keywords are used to get and set the value of the property directly or through an accessor method. For a read-only property, leave out the write portion of the declaration.

Prism also supports a shortcut syntax called implicit fields (known as auto-generated properties in C#):

property CyborgAge: Integer;

You can give properties any visibility you wish (private, protected, etc). It is common in Delphi and Delphi Prism to start member fields with "F" (FCName in our example) and drop the "F" with properties that manage member fields (CyborgName in our example).

Syntax Example:
Cyborg = class(System.Object)
private
  FCName: String;
public
  property CyborgName: String read FCName write FCName;
end;
Code Contributed By Prestwood staff member Mike Prestwood:
mprestwood
Email Approved! E CA USA

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.


Comments

Oldest To Newest

Add Comment
Author...
Prestwood IT Solutions
Staff
Moderator
Mike Prestwood
Rank: Fleet Admiral

Joined: Oct 2000
Location: Citrus Heights, CA USA
Mike Prestwood -Collapse +Expand
Email Approved! E CA USA
Comment 1 of 2
Friday, July 09, 2010

FWIW, good points. Nothing wrong with standards. I'll sweep thru and update all these examples. For what it's worth, I agree that private and protected probably could both be camel capped.


Reader...
mtiede
Rank: Cadet 3rd Year

Joined: May 2009
Location: Grand Island, NY USA
mtiede -Collapse +Expand
Email Approved! E NY USA

Member Points: 36
Visits: 19
MB Posts: 1

KB Articles: 0
Comment 2 of 2
Friday, July 09, 2010

Although I don't think Microsoft makes it indisputably clear, this link:

http://msdn.microsoft.com/en-us/library/x2dbyw72%28VS.71%29.aspx?ppud=4

Says that Properties should be Pascal Case and Protected (non-public?) instance fields should be Camel Case.

So I think in your example, CyborgName should be Pascal, as it is, but the backing field should be fcName or Camel Case.

Admittedly, they DON'T specifically say what to do with PRIVATE instance fields so that muddies the waters.  But if the backing fields are Pascal and properties are Pascal, then it gets harder to read the code and tell which is which.

Of course, personally, I think having case sensitivity in a language is dumb and the same thing goes for these kinds of "case conventions".

However, I believe that camel case for the (non-public) fields is the recommendation.

FWIW.

Would you like to comment? Reply? Ask a question? Say thanks?
+Add Comment

 KB Article #101740 Counter
674
Since 12/20/2008

Sponsored Ad
Brought to you by Prestwood IT Solutions
We hope you are enjoying our knowledge base! We welcome your participation in our open online community. As the caretakers, we pay our staff to moderate, edit, and contribute free content here in an effort to promote our software development company. Keep us in mind if you or your company needs help. Whether you need a single developer or a team, consider Prestwood. We are an American company that keeps jobs in America (no off shoring and no need for H-1B developers). Our hope is that you will put some or all of your development tasks in our hands. We specialize in hourly help (1 hour minimum), custom websites from $2k to $40k, business database applications from $5k to $60k, and enterprise application development starting from $20k. Talented Developer?
If you are a talented developer and would like to work with us, start by filling out our Register for Work form.
 
814 People Online Now!!  
Online Now: Sign In to see who's online now!  Not a member? Join Prestwood now. It's free!