自設property問題 |
答題得分者是:danny
|
bill534
一般會員 發表:38 回覆:51 積分:17 註冊:2007-02-22 發送簡訊給我 |
property BW8Image: TEBW8image read FBW8Image write SetBW8Image;
附檔中,當我指定BW8Image後,若直接從TMyImgWin的Object Inspector中刪除property則不會出錯,但直接把TEBW8image的元件ICON直接刪除的話,則會出現rtl70.bpl記憶體存取特例!為什麼會這樣呢? |
danny
版主 發表:100 回覆:522 積分:595 註冊:2002-03-11 發送簡訊給我 |
那是因為你沒有處理 Notification 的關係, 才會造成存取一個已經不存在的 Component
Component 被刪除時會通知其他 Component (有點像廣播), 你的 Component (TMyImgWin Class)要處理掉這個通知 請將以下程式加入到 Component (TMyImgWin Class) 中 [code delphi] protected { Protected declarations } procedure Notification(AComponent: TComponent; Operation: TOperation); override; ......... procedure TMyImgWin.Notification(AComponent: TComponent; Operation: TOperation); begin inherited Notification(AComponent, Operation); if (Operation = opRemove) then begin if (AComponent = BW8Image) then BW8Image:= nil; end; end; [/code] ===================引 用 bill534 文 章=================== property BW8Image: TEBW8image read FBW8Image write SetBW8Image; 附檔中,當我指定BW8Image後,若直接從TMyImgWin的Object Inspector中刪除property則不會出錯,但直接把TEBW8image的元件ICON直接刪除的話,則會出現rtl70.bpl記憶體存取特例!為什麼會這樣呢?
------
將問題盡快結案也是一種禮貌!
編輯記錄
danny 重新編輯於 2007-11-27 11:10:20, 註解 無‧
|
jow
尊榮會員 發表:66 回覆:751 積分:1253 註冊:2002-03-13 發送簡訊給我 |
(1)TMyImgWin = class(TComponent)
如果用拖拉的方式, 將一個TMyImgWin放置在一個TForm上 ,則此時TMyImgWin的Owner會是這個TForm. (2)在TMyImgWin中用到的物件, 其Owner最好設定給TMyImgWin本身 而不要使用Application這個Global TApplication物件 MyImgROI: TEBW8ROI; MyImgROI := TEBW8ROI.Create(application);<<--用Create(Self) (3)物件MyImgROI只有在run-time才產生, 最好在TMyImgWin.Create中 將它初始成nil, 其實FBW8Image也應該如此做, 並且要確保其他程式碼 在引用到這些可能為nil的物件時, 能夠正常Work. (4)以下程式碼重複判斷... procedure TMyImgWin.SetGrabAreaUsed(Value: Boolean); begin if assigned(FBW8Image) then begin if FBW8Image <> nil then begin end; end; end; (5)這裡如果指定成傳入的物件, 那在FBW8Image<>nil的情況下, 原本指向的物件, 該如何處理??? procedure TMyImgWin.SetBW8Image(Value: TEBW8image); begin FBW8Image := Value; (略) end; 以上純屬個人看法, 僅供參考... |
bill534
一般會員 發表:38 回覆:51 積分:17 註冊:2007-02-22 發送簡訊給我 |
漂亮,搞定了,謝謝啦!!
===================引 用 danny 文 章=================== 那是因為你沒有處理 Notification 的關係, 才會造成存取一個已經不存在的 Component Component 被刪除時會通知其他 Component (有點像廣播), 你的 Component (TMyImgWin Class)要處理掉這個通知 請將以下程式加入到 Component (TMyImgWin Class) 中 [code delphi] protected { Protected declarations } procedure Notification(AComponent: TComponent; Operation: TOperation); override; ......... procedure TMyImgWin.Notification(AComponent: TComponent; Operation: TOperation); begin inherited Notification(AComponent, Operation); if (Operation = opRemove) then begin if (AComponent = BW8Image) then BW8Image:= nil; end; end; [/code] ===================引 用 bill534 文 章=================== property BW8Image: TEBW8image read FBW8Image write SetBW8Image; 附檔中,當我指定BW8Image後,若直接從TMyImgWin的Object Inspector中刪除property則不會出錯,但直接把TEBW8image的元件ICON直接刪除的話,則會出現rtl70.bpl記憶體存取特例!為什麼會這樣呢? |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |