0

如果问题看起来含糊不清或令人困惑,我深表歉意。这适用于 Delphi Prism .NET。

我有一个基类,其中有一个名为矩形边界的变量。另一个类从这个类派生或继承并有权访问基类变量边界。在设计期间,编译器从基类中识别边界变量,但在调试期间,它不断为基类中的变量边界引发未知错误。因此,我的程序编译成功但无法正确运行。

这是基类和变量:

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

这是派生类:

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

这是带有基类变量的派生类的构造函数:

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;

我究竟做错了什么?谢谢,

4

1 回答 1

1

您需要在类的受保护部分中声明该变量,以使其对派生类可见。当您在没有明确说明可见性的情况下声明它时,假定您希望将其设为私有并且私有字段对派生类不可见。

于 2011-10-24T13:50:40.233 回答