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

請問self是什麼意思 ?

尚未結案
paulch
一般會員


發表:35
回覆:14
積分:9
註冊:2002-10-29

發送簡訊給我
#1 引用回覆 回覆 發表時間:2005-02-26 23:53:14 IP:61.59.xxx.xxx 未訂閱
fmLoading := TfmLoading.Create(Self); fmLoading.Show; fmLoading.Update; 1.請問上面第1行是什麼意思 ? type TfmLoading = class(TForm) Panel1: TPanel; private { Private declarations } public { Public declarations } end; var fmLoading: TfmLoading; implementation {$R *.DFM} end. 2.上面倒數第4行又是什麼意思 ? 3.請問如何在複製這些程式碼時可出現行數 ? 謝謝
MichaelChien
一般會員


發表:33
回覆:37
積分:14
註冊:2002-12-27

發送簡訊給我
#2 引用回覆 回覆 發表時間:2005-02-27 01:59:18 IP:211.76.xxx.xxx 未訂閱
動態Create一個物件(Form),此物件之擁有者就是它自已,這樣的寫法比較不會有釋放不完全的情形發生,因為它的擁有者是自已,只要在show完後釋放,就可以了。
yorkland
高階會員


發表:2
回覆:138
積分:108
註冊:2004-12-17

發送簡訊給我
#3 引用回覆 回覆 發表時間:2005-02-27 06:59:48 IP:203.67.xxx.xxx 未訂閱
Within the implementation of a method, the identifier Self references the object in which the method is called. For example, here is the implementation of TCollection? Add method in the Classes unit.    function TCollection.Add: TCollectionItem;
begin
  Result := FItemClass.Create(Self);
end;
你提的二段程式, 應該是在不同的pas檔裡。 使用Create(Self);是用來與宣告它的Parent物件做關連, 而這個Self就是目前你所在的物件。 一般來說, 當Parent被關閉時, 系統會自動把以它為Parent的子視窗一併全部關閉。 例如: 你是在TMyObject中使用了TfmLoading.Create(Self); 這個Self就是指TMyObject. 第二個問題, var是系統預設宣告一個Public變數叫fmLoading. 你可用, 可不用, 你也可以自行在其他的物件數宣告。 不過有時候, 我們會以下列的方式達到物件在整個程式中只會被呼叫同一個記憶體:
if Assigned(fmLoading) then begin
  fmLoading.show;
end else begin
  fmLoading:=TfmLoading.Create(Self);
end;
第三個問題, 我不太清楚。 不過你可以用註解的方式, 直接標示你的問題在程式碼旁邊即可。
系統時間:2024-09-29 0:50:16
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!