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

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

   ► KBProgrammingDelphi PrismOOP   Print This     

All Groups:

Next Random Article Next Random Tidbit || Narrow Topic

Random Tidbit

Part of the mo. lesson in the Oct 15 Issue of Prestwood eMag
Prism Code Snippet:
 A flashcard from our Prism Flashcards Library
 A code snippet from our Prism Code Snippets Page
Delphi Prism Class..Object (class..end..new)

Declare your class in the Interface section. Then implement the class in the Implementation section. To create an object instance, use the New keyword. Optionally, you can use Create for backword compatibility with Delphi if you turn it on in the compatibility options. Since Prism does have a garbage collector, you do not have to free the object. If you need to free either unmanaged resources or resources where "timing" is important, implement IDisposable and take control of freeing the object yourself using Dispose.

In the interface section:

Cyborg = class(System.Object)
public method IntroduceYourself();

In the Implementation section:

method Cyborg.IntroduceYourself();
MessageBox.Show("Hi, I do not have a name yet.");

On some event like a button click:

var T1: Cyborg;
T1 := New Cyborg;
  //No need to clean up with managed classes.
  //The garbage collector will take care of it.
Switch to longer article version of Delphi Prism Class..Object (class..end..new) (Delphi Prism)

More Info


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

Two criticisms. 

1. At the very beginning, I would SHOW the Type keyword before the type definition.  Otherwise it looks like it isn't required.  But it IS.  It is just part of the Type statement in later sample code.  And I would even put the Type in front of the class definition shown later.  It isn't required, but it helps readability.  Particularly if you indent the Type statements at the same level.  I would also use vertical white space to separate the types.  Again for readability.

2. Type definitions don't HAVE to go in the Interface section.  They can also go in the Implementation section.  Where it goes depends on scope.  If you want to expose the type, then put it in the Interface.  But, if it is just a type that is used within the scope of Implementation (like some sort of helper class, for instance), then put it in the Implementation.

The description makes it sound too much like the Type declaration MUST go in the interface.

I understand this is just a basic introduction, but I would be careful not to imply incorrect information.

Otherwise, good job.

Posted 8 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 = P151A1
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 #101731 Counter
Since 12/19/2008

Follow PrestwoodBoards on: 

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