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

Advanced
-Collapse +Expand Delphi To/From
To/FromCODEGuides
-Collapse +Expand Delphi Store
PRESTWOODSTORE

Prestwood eMagazine

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

   ► KBProgrammingDelphi for W...OOP   Print This     
 
Delphi OOP:
Delphi Sealed class (sealed, final)
 
Posted 14 years ago on 10/24/2008 and updated 10/15/2009
Delphi Code Snippet:
 A flashcard from our Delphi Flashcards Library
 A code snippet from our Delphi Code Snippets Page

KB101426

Languages Focus: Prevent Derivation

How do you prevent another class from inheriting and/or prevent a class from overriding a member.

Delphi Sealed class

With Delphi, use the sealed keyword to prevent a class from being inherited from and use the final keyword to prevent a method from being overridden.

Syntax Example:
type
  Robot = class sealed(TObject)
public
  procedure Speak(pSentence: String); virtual; final;
end;

Support in Previous Versions

Delphi 7 and earlier do not suppor the Sealed keyword.

Delphi for .Net 2005

Delphi for .Net (pre Prism) supports the sealed keyword. With C#, you use the sealed keyword. As you would expect, Object Pascal for .Net does implement the sealed keyword for use with Delphi for .Net.


Comments

0 Comments.
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 = P143A1
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


Linked Certification Question(s)

The following are practice certification questions with answers highlighted. These questions were prepared by Mike Prestwood and are intended to stress an important aspect of this KB post. All our practice questions are intended to prepare you generally for passing any certification test as well as prepare you for professional work.

Advanced

1 Advanced Level Question

Question #1: Multiple Choice

In later versions of Delphi, you prevent class and method inheritance with what keyword(s)?

Answer:
1. 

You prevent derivation with the final keyword for classes and the sealed keyword for methods.

type
  Robot = class final(TObject)
public
  procedure x(); virtual; sealed;
end;
2. 

You prevent derivation for classes and methods using the sealed keyword.

type
  Robot = class sealed(TObject)
public
  procedure x(); virtual; sealed;
end;
3. 

You prevent derivation for classes and methods using the final keyword.

type
  Robot = class final(TObject)
public
  procedure x(); virtual; final;
end;
4. 

You prevent derivation with the sealed keyword for classes and the final keyword for methods.

type
  Robot = class sealed(TObject)
public
  procedure x(); virtual; final;
end;
5. 

Delphi for Win32 does not support preventing of inheritance with any version of Delphi including later versions.


 KB Article #101426 Counter
18884
Since 10/24/2008
Go ahead!   Use Us! Call: 916-726-5675  Or visit our new sales site: 
www.prestwood.com


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