繼承關系中的函數 動態連結和靜態連結觀念 |
|
nathihg
一般會員 發表:5 回覆:1 積分:1 註冊:2006-08-02 發送簡訊給我 |
Unit1interface
, , , , , , , ,
DialogsStdCtrlstype
TForm1 classTForm : ;
Button2TButton : ;
procedure (: );
procedure (: );
procedure (: );
private
{ Private declarations }
public
{ Public declarations }
end = procedure (:);;
end = ()
procedure (:);; 的動態連結
end = ()
procedure ; 的靜態連結
endvar
Form1TForm1implementation
Tonemethod1parainteger ();
end Ttwomethod1paraInteger ();
end Tthreemethod1 ();
endprocedure .(: );
theoneTonebegin
theoneToneCreate .();
theonefreeendprocedure .(: );
thetwoTtwo :;
測 式
thetwoTtwoCreate :=;
theonemethod11//call Tonemethod1
因為動態連結而的
(as ).(); 的提示顯示直接Ttwomethod1
我以為使用和使用效果一樣
應該是的然後因為動態連結而的 //()call Ttwomethod1(1),不能call Tone的method1(1)
thetwomethod11//call Ttwomethod1
thetwofreeendprocedure .(: );
thethreeTthree :;
:=.;
theonethethree .(); 的 //call Tthreemethod1
thethree Tonemethod1//Delphicall Tthreemethod1
我以為使用和使用效果一樣
應該是的然後因為靜態連結所以無法的 //()call Tthreemethod1, 不能call Tone的method1(1)
.; 的 .;
;
.
我的問題是紅色的註解部份,是否是我對AS的用法有誤解呢? (搜尋AS的話,有太多有AS字串的文章了) |
psl
一般會員 發表:6 回覆:30 積分:7 註冊:2003-06-11 發送簡訊給我 |
===================引 用 文 章=================== (as ).(); 的提示顯示直接Ttwomethod1
(as ).;的提示顯示直接的
The as operator performs checked typecasts. The expression object as returns a reference to the same object as class. --------------------------------------------------------------------------------- 這一段是 as operator 的說明 很明顯的 你的 (as ) 其實是傳回物件 thetwo 的參考 所以當然會呼叫到 thetwo.method1 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |