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
[65230] Re:시작값과 마지막값을 넣고 순차적으로 리스트 생성하는 법을 알고싶습니다
제리압빠. [kamizen] 779 읽음    2011-09-26 02:43
id 를 키로 data를 가지는 자료형을 만들고 싶으신가보군요..

먼저 빌더 헬프에서 TList 를 보시면...
아래와 같은 예제 코드가 있습니다..
/*
This example creates a list object and inserts two structures into it. The value of the structure fields are written on a paintbox:
*/

typedef struct AList

{
  int I;
  char C;
} TAList;

typedef TAList* PAList;

void __fastcall TForm1::Button1Click(TObject *Sender)

{
  PAList AStruct;
  TList *MyList = new TList;
  // fill the TList
  AStruct = new TAList;
  AStruct->I = 100;
  AStruct->C = 'Z';
  MyList->Add(AStruct);
  AStruct = new TAList;
  AStruct->I = 100;
  AStruct->C = 'X';
  MyList->Add(AStruct);
  
  // Go through the list, writing the elements to the
  // canvas of a paintbox component.
  int Y = 10; // position on canvas
  for (int i = 0; i < MyList->Count; i++)
  {
    AStruct = (PAList) MyList->Items[i];
    PaintBox1->Canvas->TextOut(10, Y, IntToStr(AStruct->I));
    Y += 30;  // Increment Y Value again
    PaintBox1->Canvas->TextOut(10, Y, AStruct->C);
    Y += 30;  //Increment Y Value
  }

  // Clean up ?must free memory for the items as well as the list
  for (int i = 0; i < MyList->Count; i++)
  {
    AStruct = (PAList) MyList->Items[i];
    delete AStruct;
  }
  delete MyList;

}

상기 소스에서.. TAList 의 내부 자료형을 바꿔주시고... id , data 라고 하시니...
typedef struct {
     char c_Id[20+1];
     int     i_Data       ;
}TAList;

이렇게 바꾸시고...

자료 생성 루틴은..

for( int i = input_Start ; i <= input_End ; i++ )
{
     PAList  = new TAList;
     memset( PAList , 0x00 , sizeof( TAList ));
     sprintf( PAList ->c_Id , "abc%03d" , i );
     PAList->i_Data = i ; 
     MyList->Add( PAList );
}


해주시면... 되지 않나 싶네요... TList 자체에 Sorting 기능도 있고... 사용자가 만든 자료구조를 다 담을수 있으니깐
편리하실듯 싶습니다.
헬프에 나와 있는거 처럼... 데이타 삭제 부분 처리는 프로그램 종료 전에 ... 꼭 돌도록 해줘야... 메모리가 세는걸 막을수 있겠지용?

+ -

관련 글 리스트
65210 시작값과 마지막값을 넣고 순차적으로 리스트 생성하는 법을 알고싶습니다 김동석 1184 2011/09/22
65230     Re:시작값과 마지막값을 넣고 순차적으로 리스트 생성하는 법을 알고싶습니다 제리압빠. 779 2011/09/26
65211     Re:시작값과 마지막값을 넣고 순차적으로 리스트 생성하는 법을 알고싶습니다 aa 861 2011/09/22
Google
Copyright © 1999-2015, borlandforum.com. All right reserved.