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

刪除動態建立的圖檔物件

尚未結案
SunOS
一般會員


發表:12
回覆:7
積分:3
註冊:2003-01-07

發送簡訊給我
#1 引用回覆 回覆 發表時間:2003-01-12 01:32:13 IP:61.64.xxx.xxx 未訂閱
在FormCreate我建立一新物件 Bitmap1 = new Graphics::TBitmap1; 我想在按一Button,或FormClose才delete Bitmap1 但為甚麼不行Run??
Cooky Kid
初階會員


發表:5
回覆:68
積分:44
註冊:2002-07-11

發送簡訊給我
#2 引用回覆 回覆 發表時間:2003-01-12 02:08:11 IP:211.76.xxx.xxx 未訂閱
引言: 在FormCreate我建立一新物件 Bitmap1 = new Graphics::TBitmap1; 我想在按一Button,或FormClose才delete Bitmap1 但為甚麼不行Run??
如果這個程式中只有一個Bitmap元件的話, 就可以使用以下動態方式處理, good luck!!!
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
for(int i=0; i<Form1->ComponentCount; i  )
 if(dynamic_cast(Form1->Components[i]))
   {
   Graphics::TBitmap *tmpBitmap = (Graphics::TBitmap *)Components[i];
   delete tmpBitmap;
   }
}
//---------------------------------------------------------------------------
Cooky Kid
初階會員


發表:5
回覆:68
積分:44
註冊:2002-07-11

發送簡訊給我
#3 引用回覆 回覆 發表時間:2003-01-12 02:15:30 IP:211.76.xxx.xxx 未訂閱
引言: 在FormCreate我建立一新物件 Bitmap1 = new Graphics::TBitmap1; 我想在按一Button,或FormClose才delete Bitmap1 但為甚麼不行Run??
Sorry...不知如何了...有些程式碼lose.... 所以改成全形的>,<,.... copy時,請自行改回半形.....
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
for(int i=0; i<Form1->ComponentCount; i  )
 if(dynamic_cast<Graphics::TBitmap *>(Form1->Components[i]))
   {
   Graphics::TBitmap *tmpBitmap = (Graphics::TBitmap *)Components[i];
   delete tmpBitmap;
   }
}
//---------------------------------------------------------------------------
skcc
中階會員


發表:36
回覆:96
積分:88
註冊:2002-08-28

發送簡訊給我
#4 引用回覆 回覆 發表時間:2003-01-12 14:58:13 IP:203.99.xxx.xxx 未訂閱
首先我假設你的 Bitmap1 以在 TForm1 中設為其中之一個成員:
class TForm1 : public TForm
{
    ..
public:                // User declarations
        Graphics::TBitmap *Bitmap1; 
    ..
}
..
void __fastcall TForm1::FormCreate(TObject *Sender)
{
   this->Bitmap1=new Graphics::TBitmap();
   ..
   ..
void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action)
{
    delete this->Bitmap1;
    ..
    ..
試試這樣吧!
SunOS
一般會員


發表:12
回覆:7
積分:3
註冊:2003-01-07

發送簡訊給我
#5 引用回覆 回覆 發表時間:2003-01-12 18:16:53 IP:61.64.xxx.xxx 未訂閱
可是要如何驗證動態建立的物件已刪除?? 例如有哪個方法是可以得知動態建立的物件名稱....在刪除前執行與刪除後執行可以得知是不是真的已被刪除
RaynorPao
版主


發表:139
回覆:3622
積分:7025
註冊:2002-08-12

發送簡訊給我
#6 引用回覆 回覆 發表時間:2003-01-12 20:15:19 IP:61.221.xxx.xxx 未訂閱
引言: 可是要如何驗證動態建立的物件已刪除?? 例如有哪個方法是可以得知動態建立的物件名稱....在刪除前執行與刪除後執行可以得知是不是真的已被刪除
SunOS 你好:
(1)動態建立物件的名稱??
   假如你宣告成醬子 Graphics::TBitmap *bmp;
   bmp 就是這個物件的名稱吧
(> >
>    >
   其實可以自己寫一個簡單的 >    -- 
        
------
-- 若您已經得到滿意的答覆,請適時結案!! --
-- 欲知前世因,今生受者是;欲知來世果,今生做者是 --
-- 一切有為法,如夢幻泡影,如露亦如電,應作如是觀 --
SunOS
一般會員


發表:12
回覆:7
積分:3
註冊:2003-01-07

發送簡訊給我
#7 引用回覆 回覆 發表時間:2003-01-12 22:27:02 IP:61.64.xxx.xxx 未訂閱
我自己寫了一個印證的Function Button1的作用是顯示元件名稱,我放了兩個TButton,在 FormCreate中建立Bitmap1物件,但只顯示TButton兩次...似乎BCB察覺不到? 我想做的驗證是..按Button1顯示所有的物件名稱,因在FormCreate已建立一 TBitmap物件,所以在按Button2刪除之後,再按Button1顯示所有的物件名稱應該 要少一個TBitmap物件才對.但似乎都一樣,怪.... 在Unit1.cpp //---------------------------------------------------------------- void __fastcall TForm1::Button1Click(TObject *Sender) for (int Index = 0; Index < Form1->ComponentCount; Index ) { Graphics::TBitmap *Bitmap1 = (Graphics::TBitmap *)Components[Index]; ShowMessage(Bitmap1->ClassName()); } //---------------------------------------------------------------- void __fastcall TForm1::FormCreate(TObject *Sender) { Bitmap1=new Graphics::TBitmap(); } //------------------------------------------------------------------- void __fastcall TForm1::Button2Click(TObject *Sender) { delete Bitmap1; } //----------------------------------------------------------------- 在Unit1.h //---------------------------------------------------------------- public: // User declarations Graphics::TBitmap *Bitmap1; //-------------------------------------------------------------- 發表人 - SunOS 於 2003/01/12 22:29:44
RaynorPao
版主


發表:139
回覆:3622
積分:7025
註冊:2002-08-12

發送簡訊給我
#8 引用回覆 回覆 發表時間:2003-01-12 22:53:22 IP:61.221.xxx.xxx 未訂閱
引言: 我自己寫了一個印證的Function Button1的作用是顯示元件名稱,我放了兩個TButton,在 FormCreate中建立Bitmap1物件,但只顯示TButton兩次...似乎BCB察覺不到? 我想做的驗證是..按Button1顯示所有的物件名稱,因在FormCreate已建立一 TBitmap物件,所以在按Button2刪除之後,再按Button1顯示所有的物件名稱應該 要少一個TBitmap物件才對.但似乎都一樣,怪.... 在Unit1.cpp
SunOS 你好: 請問你有仔細看過 Components, ComponentCount 在 bcb help 中的說明嗎?? < class="code"> TComponent::Components Lists all components owned by the component. __property TComponent* Components[int Index] = {read=GetComponent}; Description Use Components to access any of the components owned by this component, such as the components owned by a form. The Components property is most useful when referring to owned components by number rather than name. It is also used internally for iterative processing of all owned components. Note: For convenience use Components with ComponentCount for iterative processing.
TComponent::ComponentCount
Indicates the number of components owned by the component.    __property int ComponentCount = {read=GetComponentCount, nodefault};    Description    Use ComponentCount to find or verify the number of components owned by a component, or when iterating through the Components list to perform some action on all owned components. ComponentCount is used internally for such iterative procedures.    Note:        The ComponentCount of a component contains the same number of items as in the Components list for that component. 
-- Enjoy Researching & Developing --
------
-- 若您已經得到滿意的答覆,請適時結案!! --
-- 欲知前世因,今生受者是;欲知來世果,今生做者是 --
-- 一切有為法,如夢幻泡影,如露亦如電,應作如是觀 --
SunOS
一般會員


發表:12
回覆:7
積分:3
註冊:2003-01-07

發送簡訊給我
#9 引用回覆 回覆 發表時間:2003-01-12 23:34:49 IP:61.64.xxx.xxx 未訂閱
各位大大: 這樣的印證是對的,當你在Button1Click中把Image1->Canvas->Draw(0,0,B) 與delete B對調會產生錯誤,因為Image1元件無法載入一空物件,所以物件的確 被刪除,故得證 //----------------------------------------------------- 在Unit1.c中宣告 //----------------------------------------------------- void __fastcall TForm1::Button2Click(TObject *Sender) { B=new Graphics::TBitmap; B->LoadFromFile("animp.bmp"); B->TransparentColor=clWhite; B->Transparent=true; } //----------------------------------------------------- void __fastcall TForm1::Button1Click(TObject *Sender) { Image1->Canvas->Draw(0,0,B); delete B; } //----------------------------------------------------- 在Unit1.h中宣告 //----------------------------------------------------- public: // User declarations Graphics::TBitmap *B;
系統時間:2024-04-27 3:25:52
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!