線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:814
推到 Plurk!
推到 Facebook!

As 錯誤(搭配 TList)

尚未結案
s07452
一般會員


發表:20
回覆:16
積分:7
註冊:2003-11-17

發送簡訊給我
#1 引用回覆 回覆 發表時間:2004-04-01 17:44:27 IP:61.56.xxx.xxx 未訂閱
這是延續上一個 TObjectList 的問題,但上串已經結案了,所以另起爐灶,若造成閱讀不便,歹勢。     
 
  PAA=^TAA;
  TAA= class(TObject)
    。。。
    procedure show;
  end;    procedure TForm1.FormCreate(Sender: TObject);
begin
  a:= TAA.Create(1);
  List1.Add(a);
end;    procedure TForm1.Button1Click(Sender: TObject);
begin
  (List1.Items[0] as TAA).show;      //這樣會Error
  TAA(List1.Items[0]).show;          //這樣OK
end;
william
版主


發表:66
回覆:2535
積分:3048
註冊:2002-07-11

發送簡訊給我
#2 引用回覆 回覆 發表時間:2004-04-02 10:39:52 IP:147.8.xxx.xxx 未訂閱
The as operator makes use of the RTTI before typecasting and it can work on interfaces, too. Typecast using Txxx() is much faster than the as operator since there will be no checking. According to my experience, the as operator sometimes behave strangely (e.g. D6 ok while D5 error???) and personally I would only use as when typecasting interface, for objects I always use the direct typecast.
系統時間:2024-05-16 23:18:31
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!