📄 shapes.~pas
字号:
unit Shapes;interfaceuses SysUtils, Classes, Types, QGraphics;type TGeoShape = class( TObject )
public
function Draw(): string; virtual;
end;
TGeoPoint = class( TGeoShape )
protected
FPoint: TPoint;
public
// Error 1.
// function Draw(): string; virtual; override;
// Error. Field definition not allowed after methods or properties
// Only use
// function Draw(): string; override;
// NOT allowed to define it using virtual again.
// Error 2.
// procedure Draw( Canvas: TCanvas );
// Error. Overloaded procedure 'Draw' must be marked with the 'overload' directive
// Error 3.
// procedure Draw( Canvas: TCanvas ); overload;
// Error. Previous declaration of 'Draw' was not marked with the 'overload' directive
// Error 4.
// function Draw( Canvas: TCanvas ): string; reintroduce; overload;
// This statement can work if no virtual method Draw has been defined again.
// But if:
// If the virtual method Draw has been defined again in the current class,
// Error. Previous declaration of 'Draw' was not marked with the 'overload' directive
// We Can NOT use it.
// Error 5.
// Error. Overloaded procedure 'Draw' must be marked with the 'overload' directive
// If needs an overload Draw and override, must use
function Draw( Canvas: TCanvas ): string; reintroduce; overload;
function Draw(): string; reintroduce; overload; override;
// This statement is error.
// function Draw(): string; override;
end;
TGeoLine = class( TGeoPoint )
protected
FToPoint: TPoint;
public
function Draw(): string; override;
end;
TGeoRect = class( TGeoShape )
protected
FRect: TRect;
public
function Draw(): string; override;
end;
{var Shape: TGeoShape; Point: TGeoPoint; Line: TGeoLine; Rect: TGeoRect;}implementation{ TGeoShape }function TGeoShape.Draw: string;begin Result := 'TGeoShape.Draw called.';end;{ TGeoPoint }function TGeoPoint.Draw: string;begin Result := 'TGeoPoint.Draw called.';end;function TGeoPoint.Draw(Canvas: TCanvas): string;begin Result := 'TGeoPoint.Draw(Canvas) called.';end;{ TGeoLine }function TGeoLine.Draw: string;begin Result := 'TGeoLine.Draw called.';end;{ TGeoRect }function TGeoRect.Draw: string;begin Result := 'TGeoLine.Draw called.';end;end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -