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 Prism Member Modifiers
Prism supports a full suite of member modifiers. Prism virtuality modifiers are virtual, override, final, and reintroduce.
Prism general modifiers are abstract, empty, async, external, locked, unsafe, implements, and iterator.
Not all member types support all member modifiers. For example, member fields support only readonly and implements.
Syntax Example: Cyborg = public class(System.Object)
public
method Speak(pMessage: String); virtual;
end;
Series888 = public class(Cyborg)
public
method Speak(pMessage: String); override;
end;
Complete Example
The following is a complete example using the class above. It assumes a form with a button on it.
namespace CR_MemberModifiers;
interface
uses
System.Drawing,
System.Collections,
System.Collections.Generic,
System.Linq,
System.Windows.Forms,
System.ComponentModel;
type
/// <summary>
/// Summary description for MainForm.
/// </summary>
MainForm = partial class(System.Windows.Forms.Form)
private
method button1_Click(sender: System.Object; e: System.EventArgs);
protected
method Dispose(disposing: Boolean); override;
public
constructor;
end;
Cyborg = public class(System.Object)
public
method Speak(pMessage: String); virtual;
end;
Series888 = public class(Cyborg)
public
method Speak(pMessage: String); override;
end;
implementation
{$REGION Construction and Disposition}
constructor MainForm;
begin
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
end;
method MainForm.Dispose(disposing: Boolean);
begin
if disposing then begin
if assigned(components) then
components.Dispose();
//
// TODO: Add custom disposition code here
//
end;
inherited Dispose(disposing);
end;
{$ENDREGION}
method Cyborg.Speak(pMessage: String);
begin
//Default cyborg voice.
MessageBox.Show(pMessage);
end;
method Series888.Speak(pMessage: String);
begin
//Series 800 sounding voice.
MessageBox.Show(pMessage);
end;
method MainForm.button1_Click(sender: System.Object; e: System.EventArgs);
begin
var Vick: Series888;
Vick := New Series888;
Vick.Speak("Hello, I am Vick.");
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.