Why is it raising Run-Time Unknown Identifier error for a variable from within a base class?

170 views Asked by At

If the question seems vague or confusing, I apologize. This is for Delphi Prism .NET.

I have a base class with a variable called bounds of type rectangle. From this class another class derives or inherits and has access to base class variable bounds. During design time, compiler recognizes bounds variable from base class, but during debug-time it keeps raising unknown error for the variable bounds in base class. So, my program compiles successfully but fails to run correctly.

Here is the base class and the variable:

  TControlObject = public class
    bounds:Rectangle;     <<=========This is the Variable in question
  private
  protected
  public
  end; 

Here is the derived class:

  TGateControl = class(TControlObject)
    fInputCount:SmallInt;
  private
  protected
  public
    constructor (theForm:Form);
  end;

Here is the constructor for the derived class with the base class variable:

constructor TGateControl(theForm:Form);
begin
  inherited constructor(theForm);
  fInputCount := 2;
  bounds.width := bounds.Right-(bounds.left+(4 * CGridSize)); <<=======Here is where unknown identifier error is raised for bounds variable.
  bounds.Height := bounds.Bottom-(bounds.top+(3 * CGridSize));<<=======Here is where unknown identifier error is raised for bounds variable.
end;

What am I doing wrong? Thanks,

1

There are 1 answers

1
Sebastian P.R. Gingter On BEST ANSWER

You need to declare the variable in the protected section of the class to make it visible to derived classes. When you declare it without explicitely stating the visibility, it is assumed that you wanted to make it private and a private field is not visible to derived classes.