Last active
February 16, 2021 11:24
-
-
Save Al-Muhandis/d46d4ab8eb00ec5454931d48da9e37fa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
unit Unit1; | |
{$mode objfpc}{$H+} | |
interface | |
uses | |
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls; | |
type | |
{ TForm1 } | |
TForm1 = class(TForm) | |
Button1: TButton; | |
Edit1: TEdit; | |
procedure Button1Click(Sender: TObject); | |
private | |
public | |
end; | |
var | |
Form1: TForm1; | |
implementation | |
uses | |
Unit2; | |
{$R *.lfm} | |
{ TForm1 } | |
procedure TForm1.Button1Click(Sender: TObject); | |
var | |
aManager: TManagerClass; | |
begin | |
aManager:=TManagerClass.Create; | |
Edit1.Text:=aManager.Item.GetAlias; | |
aManager.Free; | |
end; | |
end. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
unit Unit2; | |
{$mode objfpc}{$H+} | |
interface | |
uses | |
Classes, SysUtils; | |
type | |
{ TBaseClass } | |
TBaseClass = class | |
public | |
class function GetAlias: String; | |
end; | |
{ TDescendantOfBaseClass } | |
TDescendantOfBaseClass = class(TBaseClass) | |
public | |
class function GetAlias: String; | |
end; | |
{ TManagerClass } | |
TManagerClass = class | |
private | |
FItem: TBaseClass; | |
procedure SetItem(AValue: TBaseClass); | |
public | |
constructor Create; | |
destructor Destroy; override; | |
property Item: TBaseClass read FItem write SetItem; | |
end; | |
implementation | |
{ TManagerClass } | |
procedure TManagerClass.SetItem(AValue: TBaseClass); | |
begin | |
if FItem=AValue then Exit; | |
FItem:=AValue; | |
end; | |
constructor TManagerClass.Create; | |
begin | |
FItem:=TDescendantOfBaseClass.Create; | |
end; | |
destructor TManagerClass.Destroy; | |
begin | |
FItem.Free; | |
inherited Destroy; | |
end; | |
{ TDescendantOfBaseClass } | |
class function TDescendantOfBaseClass.GetAlias: String; | |
begin | |
Result:='Descendant'; | |
end; | |
{ TBaseClass } | |
class function TBaseClass.GetAlias: String; | |
begin | |
Result:=EmptyStr; | |
end; | |
end. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment