我有一个如下结构的类:
TCommonProperties = class(TObject)
protected
procedure methodMake; virtual;
end;TParent = class(TObject)
public
property CommonProperties: TCommonProperties read ... write ...;
end;TChild = class(TParent)
published
property CommonProperties;
end;这时,我写一个新类,继承TChild:
TMyClass = class(TChild)
end;在TMyClass中,我要覆盖methodMake,可以做到吗?如果可以,该如何做?
谢谢
TCommonProperties = class(TObject)
protected
procedure methodMake; virtual;
end;TParent = class(TObject)
public
property CommonProperties: TCommonProperties read ... write ...;
end;TChild = class(TParent)
published
property CommonProperties;
end;这时,我写一个新类,继承TChild:
TMyClass = class(TChild)
end;在TMyClass中,我要覆盖methodMake,可以做到吗?如果可以,该如何做?
谢谢
TMyClass = class(TChild)
protected
procedure methodMake; override;
end;
protected
procedure methodMake;
end;
就可以了,因为你没有继承TCommonProperties类,继承用overload
procedure methodMake; overload;
...
若覆盖,则应该:
TCommonProperties = class(TObject)
protected
procedure methodMake; virtual;
end;TParent = class(TCommonProperties )
public
property CommonProperties: TCommonProperties read ... write ...;
end;TChild = class(TParent)
published
property CommonProperties;
end;TMyClass = class(TChild)
protected
procedure methodMake; override;end;
protected
procedure methodMake;
end;
就可以了,因为你没有继承TCommonProperties类,继承用overload
若覆盖,则应该:
TCommonProperties = class(TObject)
protected
procedure methodMake; virtual;
end;TParent = class(TCommonProperties )
public
property CommonProperties: TCommonProperties read ... write ...;
end;TChild = class(TParent)
published
property CommonProperties;
end;TMyClass = class(TChild)
protected
procedure methodMake; override;end;