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     
  From the December 2015 Issue of Prestwood eMag
 
Delphi OOP:
Delphi Member Modifiers
 
Posted 16 years ago on 12/22/2008 and updated 2/21/2009
Delphi Code Snippet:
 A flashcard from our Delphi Flashcards Library
 A code snippet from our Delphi Code Snippets Page

KB101752

Languages Focus: Member Modifier

Traditional private, protected, public, etc. member modifiers are documented under the member visibility topic of the Cross Reference Encyclopedia. With member modifiers here, we address additional member modifiers such as method and field modifiers.

Delphi Member Modifiers

Specify Delphi member modifiers as follows:

reintroduce; overload; [binding modifier]; [calling convention]; abstract; [warning]

The binding modifiers are virtual, dynamic, or override.

The calling conventions are register, pascal, cdecl, stdcall, or safecall.

The warnings are platform, deprecated, or library.

Additional directives include reintroduce, abstract, class, static, overload, and message.

Syntax Example:
TCyborg = class(TObject)
public
  procedure Speak(pMessage: String); virtual;
end;
 
TSeries888 = class(TCyborg)
public
  procedure Speak(pMessage: String); override;
end;

Complete Example

The following is the form unit code demonstrating the class above. It assumes a form with a button on it. Note that you add the member modifiers to the member declaration but not when you implement it.

unit MemberModifiersUnit;
 
interface
 
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

  TCyborg = class(TObject)
  public
    procedure Speak(pMessage: String); virtual;
  end;

  TSeries888 = class(TCyborg)
  public
    procedure Speak(pMessage: String); override;
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
  Vick: TSeries888;
begin
  Vick := TSeries888.Create;
  Vick.Speak('Hello, I am Vick.');
end;

{ TCyborg }
procedure TCyborg.Speak(pMessage: String);
begin
  //Default cyborg voice.
  ShowMessage(pMessage);
end;

{ TSeries888 }
procedure TSeries888.Speak(pMessage: String);
begin
  //Series 888 voice.
  ShowMessage(pMessage);
end;

end.

More Info


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 = P161A1
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.

Beginner

1 Beginner Level Question

Question #1: True or False?

Delphi uses the keyword Overridable to define a virtual method in a parent class and the keyword Overrides to replace the method in a descendant class.

Answer:
  • True
  • False

  •  KB Article #101752 Counter
    13798
    Since 12/22/2008
    Sales Website: www.prestwood.com Or visit our legacy sales site: 
    legacy.prestwood.com


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