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