Материалы сайта
Это интересно
Языки программирования
unit polimor_ ; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type Tform1 = class(TForm) Edit1: TEdit; Edit2: TEdit; GroupBoxl: TGroupBox; RadioButtonI: TRadioButton; RadioButton2: TRadioButton; Label1: TLabel; Label2: TLabel; Button1: TButton; Button2: TButton; procedure Button1Click (Sender: TObject); procedure Button2Click (Sender: TObject); private { Private declarations } public { Public declarations } end; type TPerson=class fname: string; { имя } constructor Create (name: string); function info: string; virtual; end; TStud=class (TPerson) fgr: integer; { номер группы } constructor Create (name: string; gr: integer) ; function info: string; override; end; TProf=class (TPerson) fdep: string; { название кафедры } constructor Create (name: string; dep: string); function info: string; override; end; const SZL=10; // размер списка var Form1: Tform1 ; List: array[1..SZL] of TPerson; // список n: integer; // кол-во людей в списке implementation {$R *.DEM} constructor TPerson.Create (name: string) ; begin fname:=name; end; constructor TStud.Create(name:string;gr:integer); begin inherited create (name); fgr:=gr; end; constructor TProf.create(name:string; dep:string); begin inherited create (name) ; fdep:=dep; end; function TPerson.Info: string; begin result:=fname; end; function TStud.Info: string ; begin result:=fname+' гp. '+IntToStr(fgr); end; function TProf.Info: string; begin result :=fname+' каф. '+fdep; end; // добавить элемент в список procedure Tform1.Button1Click (Sender: TObject); begin if n<=SZL then begin if Radiobutton1.Checked then // создадим объект TStud List[n]:=TStud.Create (Edit1.Text, StrToInt (Edit2.Text)) else List[n]:=TProf.Create (Edit1.Text, Edit2.Text); n:=n+1; end else ShowMessage (‘Список заполнен!’ ); end; procedure Tform1.Button2Click(Sender: TObject); var i:integer; st:string; begin for i:=1 to SZL do if list[i] <> NIL then st:=st+list[i].info+#13; ShowMessage( ' Список '+#13+st) ; end; end.