Specify Multiple Interfaces
You can also specify more than one interface to implement. Just separate each interface with a comma.
Cyborg600 = public class(Cyborg, IChat, IMove, IAdvancedMove)
end;
Working WinForms Example
The following example demonstrates implementing a very simple interface. The interface is named IHuman which includes one property and one method. Our resulting class is named CyborgHuman and, for clarity, our CyborgHuman class also inherits from a class called Cyborg.
Create a form and place a button on it and alter the code as follows:
namespace CR_Interfaces;
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;
IHuman = interface
property HumanName: String read write;
procedure Speak(pSentence: String);
end;
Cyborg = public class(System.Object)
end;
CyborgHuman = public class(Cyborg, IHuman)
private
FHumanName: String;
public
property HumanName: String read FHumanName write FHumanName;
procedure Speak(pSentence: String);
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}
procedure CyborgHuman.Speak(pSentence: String);
begin
MessageBox.Show(pSentence);
end;
method MainForm.button1_Click(sender: System.Object; e: System.EventArgs);
begin
var MyRobot: CyborgHuman;
MyRobot := New CyborgHuman;
MyRobot.HumanName := "Nicole";
MyRobot.Speak("Hi, my name is " + MyRobot.HumanName + ".");
end;
end.