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 기능도 있고... 사용자가 만든 자료구조를 다 담을수 있으니깐
편리하실듯 싶습니다.
헬프에 나와 있는거 처럼... 데이타 삭제 부분 처리는 프로그램 종료 전에 ... 꼭 돌도록 해줘야... 메모리가 세는걸 막을수 있겠지용?
|