inherited Create(AOwner) 與inherited差別 |
答題得分者是:careychen
|
cubi
初階會員 發表:56 回覆:94 積分:35 註冊:2002-04-15 發送簡訊給我 |
|
careychen
尊榮會員 發表:41 回覆:580 積分:959 註冊:2004-03-03 發送簡訊給我 |
一模一樣無差別, 在 inherited 的後面如果沒有打的話, 會自動找被繼承者相同的函式名
Ex: 如你的問題所示 但我也可以如下的方式: [code delphi] //被繼承者 procedure TParent.Test1; begin end; //繼承者 procedure TChild.Test1; begin inherited; // 自動繼承 Parent 的 Test1 end; procedure TChild.Test2; begin inherited Test1; // 雖然本身是 Test2 , 但可以呼叫 Parent 的 Test1 end; //所以我們可以這樣說 inherited 是用來呼叫 父物件 的一種方法 //當然也可以像下面這樣呼叫 // 但請注意如此一來, 之後維護的問題會產生更多的問題而且我們是在寫 OO 的程式 // 遵照 OO 的方式來寫才是最標準的 procedure TChild.Test3; begin inherited; // 呼叫 Parent 的 Test3 inherited Test1; // 呼叫 Parent 的 Test1 inherited Test2; //呼叫 Parent 的 Test2 end; [/code] ===================引 用 cubi 文 章=================== 請教各位前輩,下面兩種方式的差別在哪裡呢,感激不盡 constructor TMyTest.Create(AOwner: TComponent); begin inherited Create(AOwner); end; constructor TMyTest.Create(AOwner: TComponent); begin inherited; end;
------
價值的展現,來自於你用哪一個角度來看待它!!
編輯記錄
careychen 重新編輯於 2008-08-23 20:40:14, 註解 無‧
|
cubi
初階會員 發表:56 回覆:94 積分:35 註冊:2002-04-15 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |