繼承問題。(20分)

L

leway

Unregistered / Unconfirmed
GUEST, unregistred user!
type
TMyForm = class(TForm)
private
{Private declarations}
procedure MouseDown(Button: TMouseButton;
Shift: TShiftState; X, Y: Integer); override; //重載
public
{ Public declarations }
end;

procedure TMyForm.MouseDown(Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var
lab: TLabel;
begin
inherited;
lab:= Tlabel.Create(self);
lab.Parent:= self;
end;

運行報錯: Overriding virtual method 'TMyForm.MouseDowm' has lower visibility (private) than the base class 'TForm'(protected)
我想實現它該怎麼辦,請指教。謝謝!
 
你把函数声明放在public部分,因为祖先声明为protected部分,子类不应比祖先保护
级别高
 
我把函数声明放在public部分,但TMyForm.Create(self)時報錯:'Resource TMyForm not Found'
var
NewForm: TMyForm;
begin
NewForm:= TMyForm.Create(self);
end;
 
同意楼上
 
怎麼沒人回答呀?
 
procedure MouseDown(Button: TMouseButton;
Shift: TShiftState; X, Y: Integer); override;

//////////////////////////////////////////////////////////////
满足重载的条件吗?
如果不满足就直接响应WM_MOUSEDOWN消息处理吧。
 
to:wlmmlw
請舉例說得詳細些。
 
TMyForm.Create(self)時報錯:'Resource TMyForm not Found'
是什麼原因?
 
TMyForm.Create(nil)
TMyForm.Create(application)
应该这时候myform还未建,self指得就是myform把
 
to:一生中最爱
我沒明白你的意思,請說得詳細些。
 
试一试
TMyForm.Create(application);

 
TMyForm.Create(application);也不行。
 
沒人拉,來人啊!我好急。
 
不小心把这行删掉了吧?

{$R *.dfm}
 
{$R *.dfm}沒有刪除掉。
急死了,我把代碼貼出來,請大家看看,萬分感謝!
unit MyFormClass;
interface
uses
Forms,MyClassType;
type
TMyForm = class(TForm)
private
{Private declarations}
// procedure InitList;
public
{ Public declarations }
ListStatic: LinkLabel;
ListEdit: LinkEdit;
ListButton: LinkButton;
CurObject: TObject;
Lblno: integer;
Edtno: integer;
Btnno: integer;
LblCount: integer;
EdtCount: integer;
BtnCount: integer;
flg_CreateCmpnt: integer;
//procedure MouseDown(Button: TMouseButton;
// Shift: TShiftState; X, Y: Integer); override;
end;
implementation
end.

unit frmMaster;
............
............
type
TfmMaster = class(TForm)
..............
..............
procedure NewForm;
..............
private
{ Private declarations }
public
{ Public declarations }
FormNO: integer;
end;

procedure TfmMaster.NewForm;
var
NewForm: TMyForm;
begin
inc(FormNO);
NewForm:= TMyForm.Create(application); //編譯通過了,但執行到此報錯:'Resource TMyForm not Found'
NewForm.Caption:= 'Newform'+inttostr(FormNO);
NewForm.Name:= 'Form'+ inttostr(FormNO);
NewForm.Left:= 255;
NewForm.Top:= 160;
NewForm.Height:= 574;
NewForm.Width:= 732;
NewForm.Show;
end;

 
班主進來看看。
 
没见有这行[red]({$R *.dfm})[/red]阿, 贴完整点....
 
可能是没{$R *.dfm}
 
原因我找到了,TMyForm不能直接繼承TForm。
正確的做法是,在程序設計期間,用delphi的按鈕建一個窗體TFmParent,然後TMyForm從TFmParent繼承下來。這樣就可以了,但我又遇到新的問題。
我想在TMyForm中override OnMouseDown方法,實驗發現OnMouseDown不能被override 。我該如何實現,請各位指教。謝謝。
 
直接响应WM_MOUSEDOWN消息处理不是很省事吗?
奇怪。。。。。。。
 

Similar threads

顶部