Class Description:
unit unit2;
interface Type TCircle = class private ciArea:real; protected ciradius:integer; procedure setciArea; public property cirradius: integer read ciradius; property cirarea : real read ciArea; constructor create(radius:integer); end; TCylinder = class(TCircle) private cyArea:real; protected cyradius,cyheight:integer; procedure setcyArea; public property cylradius: integer read cyradius; property cylheight: integer read cyheight; property cylarea : real read cyArea; constructor create(radius, height:integer); end; implementation constructor Tcircle.Create(radius:integer); begin ciradius:= radius; setciArea; end; constructor TCylinder.create(radius,height:integer); begin cyradius:= radius; cyheight:= height; setcyArea; end; procedure TCircle.setciArea; begin ciArea:=cirradius*cirradius*3.14; end; procedure TCylinder.setcyArea; begin cyArea:=2*3.14*cylradius*(cylradius+cylheight); end; end.
Software module:
procedure TCircles.Button1Click(Sender: TObject); var a,b:integer; begin if RadioGroup1.ItemIndex=-1 then begin ShowMessage('Выберите фигуру'); end; if (Shape is TCircle) then begin a:=strtoint(edit1.Text); shape:=Tcircle.create(a); label3.Caption:='Площадь окружности = ' + floattostr(shape.cirarea); end; if (Shape is TCylinder) then begin a:=strtoint(edit1.Text); b:=strtoint(edit2.Text); shape:=Tcylinder.create(a,b); //label3.Caption:='Площадь цилиндра = ' + floattostr(shape.cylarea); end; end;
The problem occurs on the "commented out" line:
[DCC Error] Unit1.pas (60): E2003 Undeclared identifier: 'cylarea'
The error occurs due to the fact that we work with the base class and its descendant, so when we call the descendant class, do we get an error, or is it related to something else? And how to avoid this error, if I need to maintain the class hierarchy for this program, without abstract classes?