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

[BCB]動態產生物件之後的問題

答題得分者是:dllee
qqo
一般會員


發表:2
回覆:2
積分:0
註冊:2003-04-07

發送簡訊給我
#1 引用回覆 回覆 發表時間:2003-05-03 23:27:13 IP:61.231.xxx.xxx 未訂閱
請問    動態產生 5 個相同的元件 之後  怎麼區別之間 event 的觸發 ...?    ex: for(int ci=0;ci<5;ci ) { image[ci] = new TImage(this); image[ci]->Parent=this; image[ci]->Picture->LoadFromFile("xx"); image[ci]->PopupMenu=ppm2; image[ci]->SetBounds(x,x,x,x); } 然後我想 對 image 按右鍵 delete... ><" 例如 image[0] 上按右鍵 之後image[0]會delete image[1] 上按右鍵 之後image[1]會delete 有什麼發法可以區別 每個動態產生元件的event嗎 < > 新手上路< > 感謝各位大大指教>"< 發表人 - qqo 於 2003/05/03 23:38:14
dllee
站務副站長


發表:321
回覆:2519
積分:1711
註冊:2002-04-15

發送簡訊給我
#2 引用回覆 回覆 發表時間:2003-05-04 10:33:41 IP:203.204.xxx.xxx 未訂閱
//----------------------------------------------------------------------------//
__fastcall TForm1::TForm1(TComponent* Owner)
  : TForm(Owner)
{
  for(int i=0;i<5;i  )
  {
    image[i]=new TImage(this);
    image[i]->Parent=this;
    image[i]->Width=100;
    image[i]->Height=100;
    image[i]->Left=i*20;
    image[i]->Top=i*10;
    for(int x=0;x<100;x  )
      for(int y=0;y<100;y  )
       image[i]->Canvas->Pixels[x][y]=0x00FF0000>>i;
    image[i]->ImageMouseDown;
  }
}
//----------------------------------------------------------------------------//
void __fastcall TForm1::ImageMouseDown(TObject *Sender,
      TMouseButton Button, TShiftState Shift, int X, int Y)
{
  if(Button==mbRight)
  {
    TImage *img=dynamic_cast<TImage *>(Sender);
    if(img!=NULL)
      delete img;
  }
}
//----------------------------------------------------------------------------//
這樣每一個點個右鍵就刪除了。 如果還要分,可以為每個元件取名:
//----------------------------------------------------------------------------//
__fastcall TForm1::TForm1(TComponent* Owner)
  : TForm(Owner)
{
  for(int i=0;i<5;i  )
  {
    image[i]=new TImage(this);
    image[i]->Name="ImageArray" IntToStr(i);
    image[i]->Parent=this;
    image[i]->Width=100;
    image[i]->Height=100;
    image[i]->Left=i*30;
    image[i]->Top=i*20;
    for(int x=0;x<100;x  )
      for(int y=0;y<100;y  )
       image[i]->Canvas->Pixels[x][y]=0x00FF0000>>i;
    image[i]->ImageMouseDown;
  }
}
//----------------------------------------------------------------------------//
void __fastcall TForm1::ImageMouseDown(TObject *Sender,
      TMouseButton Button, TShiftState Shift, int X, int Y)
{
  if(Button==mbRight)
  {
    TImage *img=dynamic_cast<TImage *>(Sender);
    if(img!=NULL)
    {
      ShowMessage(img->Name " deleted!");
      delete img;
      img=NULL;
    }
  }
}
//----------------------------------------------------------------------------//
沒空更新的網頁... http://dllee.ktop.com.tw C及指標教學,計算機概論,資訊管理導論... http://big5.to/吃軟也吃硬 http://coolsite.to/ushells 介紹Shells,LiteStep,GeoShell.... 發表人 - dllee 於 2003/05/04 10:37:53
------
http://www.ViewMove.com
qqo
一般會員


發表:2
回覆:2
積分:0
註冊:2003-04-07

發送簡訊給我
#3 引用回覆 回覆 發表時間:2003-05-04 11:50:02 IP:61.231.xxx.xxx 未訂閱
^^y 感謝 大大的幫助...
系統時間:2024-05-08 1:04:54
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!