C++Builder Programming Forum
C++Builder  |  Delphi  |  FireMonkey  |  C/C++  |  Free Pascal  |  Firebird
볼랜드포럼 BorlandForum
 경고! 게시물 작성자의 사전 허락없는 메일주소 추출행위 절대 금지
C++빌더 포럼
Q & A
FAQ
팁&트릭
강좌/문서
자료실
컴포넌트/라이브러리
메신저 프로젝트
볼랜드포럼 홈
헤드라인 뉴스
IT 뉴스
공지사항
자유게시판
해피 브레이크
공동 프로젝트
구인/구직
회원 장터
건의사항
운영진 게시판
회원 메뉴
북마크
볼랜드포럼 광고 모집

C++빌더 Q&A
C++Builder Programming Q&A
[41570] Re:TImage..
evergreen [heredity] 947 읽음    2005-08-21 16:32
생성된 TImage 객체는 TList등 재 사용할 수 있도록 보관 후 사용해야 합니다.
아래는 간단한 사용 예를 보였습니다.
  1. "그림 추가" 버튼을 누르면 Windows Folder에 있는 그림(깃털, 낙시, .. 등)을 화면에 추가
  2. ComboxBox 선택시 선택된 그림 제거
- heredity -


*** Unit.H ***

    //---------------------------------------------------------------------------
    #ifndef Unit1H
    #define Unit1H
    //---------------------------------------------------------------------------
    #include <Classes.hpp>
    #include <Controls.hpp>
    #include <StdCtrls.hpp>
    #include <Forms.hpp>
    //---------------------------------------------------------------------------
    class TForm1 : public TForm
    {
    __published:
      void __fastcall Button1Click(TObject *Sender);
      void __fastcall cbEraseChange(TObject *Sender);
    private:/
    public:
      __fastcall TForm1(TComponent* Owner);
    };
    //---------------------------------------------------------------------------
    extern PACKAGE TForm1 *Form1;
    //---------------------------------------------------------------------------
    #endif


*** Unit.CPP ***

    //---------------------------------------------------------------------------
    #include <vcl.h>
    #pragma hdrstop

    #include "Unit1.h"
    //---------------------------------------------------------------------------
    #pragma package(smart_init)
    #pragma resource "*.dfm"
    TForm1 *Form1;

    TList *g_plstImage;
    TComboBox *g_cbErase;
    //---------------------------------------------------------------------------
    __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner)
    {
      g_plstImage = new TList();

      TButton * pbtn = new TButton( this );
      pbtn->Parent   = this;
      pbtn->Left     = 0;
      pbtn->Top      = 0;
      pbtn->Caption  = "그림추가";
      pbtn->OnClick  = Button1Click;

      g_cbErase           = new TComboBox( this );
      g_cbErase->Parent   = this;
      g_cbErase->Left     = 0;
      g_cbErase->Top      = 30;
      g_cbErase->Width    = 200;
      g_cbErase->OnChange = cbEraseChange;
    }
    //---------------------------------------------------------------------------
    void __fastcall TForm1::Button1Click(TObject *Sender)
    {
      if( g_plstImage != NULL ) {
        PCHAR  apchImageFile[] = {
          "C:\\Windows\\깃털.bmp",
          "C:\\Windows\\낚시.bmp",
          "C:\\Windows\\바람부는 들판.bmp",
          "C:\\Windows\\부채.bmp",
          "C:\\Windows\\붉은 꽃.bmp",
          "C:\\Windows\\붉은 카펫.bmp",
          "C:\\Windows\\붉은 회벽.bmp",
          "C:\\Windows\\비누 방울.bmp",
          "C:\\Windows\\커피 잔.bmp",
          "C:\\Windows\\파란 레이스 16.bmp",
          "C:\\Windows\\회벽.bmp"
        };
        TImage     *pimg   = new TImage( this );
        int        nImgCnt = g_plstImage->Count;
        int        nFiles  = sizeof(apchImageFile) / sizeof(apchImageFile[0]);
        PCHAR      pchFile = apchImageFile[nImgCnt % nFiles];
        int        nWidth  = Screen->Width / 10;
        int        nHeight = Screen->Height / 10;
        AnsiString asStr;

        pimg->Parent   = this;
        pimg->Left     = nImgCnt % 10 * nWidth;
        pimg->Top      = (nImgCnt / 10) * nHeight;
        pimg->Width    = nWidth;
        pimg->Height   = nHeight;
        pimg->Stretch  = true;

        if( FileExists( pchFile ) ) {
          pimg->Picture->LoadFromFile( pchFile );
        }
        else {
          pimg->Picture->Assign( NULL );
        }

        asStr.sprintf( "%d번째 그림 : %s", nImgCnt, pchFile );
        g_cbErase->Items->Add( asStr );
        g_plstImage->Add( pimg );
      }
    }
    //---------------------------------------------------------------------------
    void __fastcall TForm1::cbEraseChange(TObject *Sender)
    {
      int nIdx = g_cbErase->ItemIndex;

      if( (nIdx >= 0)  &  (nIdx < g_plstImage->Count) ) {
        TImage *pimg = (TImage *) g_plstImage->Items[nIdx];

        if( pimg != NULL ) {
          g_plstImage->Items[nIdx] = NULL;
          g_cbErase->Items->Strings[nIdx] = "삭제됨";
          delete pimg;
        }
      }
    }
    //---------------------------------------------------------------------------

이성제 님이 쓰신 글 :
: TImage를 동적생성 하고
:
: 부모를 Form1로 지정 합니다.
:
: 이 과정을 몇번 반복 하고나서
:
: 동적 생성한 것을 중간에 하나만 없애고 싶은데..
:
: Delete(TImage);
:
: 이런식으로 하니까..
:
: 마지막에 생성된것 하나만 없어지고 그 뒤론 아무 반응도 하지 않네요'';
:
: 어떻게 해야 할지 ㅠ
:
: 빠른 답변 부탁드립니다.

+ -

관련 글 리스트
41565 TImage.. 이성제 764 2005/08/20
41570     Re:TImage.. evergreen 947 2005/08/21
Google
Copyright © 1999-2015, borlandforum.com. All right reserved.