override的問題。(20分)

  • 主题发起人 主题发起人 leway
  • 开始时间 开始时间
L

leway

Unregistered / Unconfirmed
GUEST, unregistred user!
我從自建了一個窗體類TMyForm = class(TfmParent),TfmParent = class(TForm),我想在TMyForm中override MouseDown方法,可編譯總報錯:Declaration of 'MouseDown' differs from previous declaration。
我檢查過聲明和定義是一樣,這是為什麼?
代碼如下:
unit frmParent;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;
type
TfmParent = class(TForm)
private
{ Private declarations }
public
{ Public declarations }
end;
var
fmParent: TfmParent;
implementation
{$R *.dfm}
end.

unit MyFormClass;

interface
uses
Forms,MyClassType,Controls,Classes,StdCtrls,SysUtils,Dialogs,frmParent,Graphics,frmMain,common;

type
TMyForm = class(TfmParent)
private
{Private declarations}
// procedure InitList;
// moved:boolean;

public
{ Public declarations }
procedure MouseDown(Button: TMouseButton;
Shift: TShiftState; X, Y: Integer); override;
end;

implementation
uses
UseConst,frmObjInspctr,frmMaster,QControls;
//=============================================||
// Class Method MouseDown ||
//=============================================||
procedure TMyForm.MouseDown(Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
inherited;;
end.
 
过程为virtual或dynamic的才能被子类override!
 
必须通过继承重载虚类的方法后才能。
 
多人接受答案了。
 
后退
顶部