1
0
lazarus-tutorials/polymorphic class/unitmain.pas

52 lines
747 B
ObjectPascal
Raw Permalink Normal View History

2021-10-05 15:33:01 -04:00
unit unitmain;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ExtCtrls, person;
type
{ TMainform }
2021-10-08 13:28:36 -04:00
TMainform = class(TForm)
2021-10-05 15:33:01 -04:00
rgPeople: TRadioGroup;
procedure FormCreate(Sender: TObject);
procedure rgPeopleClick(Sender: TObject);
end;
var
Form1: TMainform;
implementation
{$R mainform.lfm}
{ TMainform }
procedure TMainform.FormCreate(Sender: TObject);
begin
end;
procedure TMainform.rgPeopleClick(Sender: TObject);
var p: TPerson;
begin
2021-10-08 13:28:36 -04:00
if rgPeople.ItemIndex < 0 then Exit;
// Select the appropriate Person
case rgPeople.ItemIndex of
0: p := TBeckham.Create;
1: p := TShakespeare.Create;
2: p := TWest.Create;
3: p := TBlaise.Create;
end;
p.Speak;
p.Free;
2021-10-05 15:33:01 -04:00
end;
end.