그리드에서 리스트로 저장하여 소팅하고 중복값 없애기. 하지만 실패한 소스.. 젠장..

2010. 9. 9. 11:40언어/C++ Builder

 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                // 스트링 리스트로 저장하기//

              /*  TStringList *TestTemp;
                TestTemp = new TStringList;
                for(int x = 0; x < TimeListCnt+1; x++)
                {
                        for(int y = 0; y < personCount; y++)
                        {
                                TestTemp->Add(StrToDateTime(TimeGrid->Cells[x+1][y+1]).FormatString("HH:mm")+ "," + (y+1));
                                TestTemp->Sort();
                        }
                }
                for(int jj = 0; jj < TestTemp->Count; jj++)
                {
                        if(jj+1 > TestTemp->Count)
                        {
                                return;
                        }
                        int PosTemp1 = TestTemp->Strings[jj].Pos(",");
                        AnsiString DeivceTimeTemp1 = TestTemp->Strings[jj].SubString(1, PosTemp1-1);
                        int PosTemp2 = TestTemp->Strings[jj+1].Pos(",");
                        AnsiString DeviceTimeTemp2 = TestTemp->Strings[jj+1].SubString(1, PosTemp2-1);
                        AnsiString DeviceNameTemp = TestTemp->Strings[jj+1].SubString(PosTemp2+1, TestTemp->Strings[jj+1].Length());
                        if(DeivceTimeTemp1 == DeviceTimeTemp2)
                        {
                                TestTemp->Strings[jj] + DeviceNameTemp;
                                TestTemp->Delete(jj+1);
                        }


                }


     ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                for(int jk = 0; jk < TestTemp->Count; jk++)
                {
                        ListBox2->AddItem(TestTemp->Strings[jk], Sender); */
                }

다시 해서 성공했다.. 좀 소스양이 많아지긴 했지만... ㅋ

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                // 스트링 리스트로 저장하기//

                TStringList *TestTemp;
                TestTemp = new TStringList;
                for(int x = 0; x < TimeListCnt+1; x++)
                {
                        for(int y = 0; y < personCount; y++)
                        {
                                TestTemp->Add(StrToDateTime(TimeGrid->Cells[x+1][y+1]).FormatString("HH:mm")+ "," + (y+1));    // 리스트에 담고
                                TestTemp->Sort();                                                                              // 정렬
                        }
                }

                int resultPosTemp;
                int ArrayPosTemp;
                for(int cntTemp = 0; cntTemp < TestTemp->Count; cntTemp++)
                {
                        ListOverrap(TestTemp ,TestTemp->Strings[cntTemp], cntTemp);
                        if(resultTemp != NULL){
                                resultPosTemp = resultTemp.Pos(",");
                                resultTemp = resultTemp.SubString(resultPosTemp, resultTemp.Length());
                                TestTemp->Strings[cntTemp] = TestTemp->Strings[cntTemp] + resultTemp;
                                resultTemp = NULL;
                        }else{
                                ;
                        }
                }

                for(int jk = 0; jk < TestTemp->Count; jk++)
                {
                        Memo2->Lines->Add(TestTemp->Strings[jk]);
                }


     ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////

void __fastcall TAdminPage::ListOverrap(TStringList *tList, AnsiString Key, int nCount)  // 검색 (순차검색) 알고리즘
{
        int KeyPos = Key.Pos(",");
        AnsiString Key1 = Key.SubString(1, KeyPos-1);

        for(int i = 0; i < tList->Count; i++)
        {
                if(nCount != i){
                        int ArrayPos = tList->Strings[i].Pos(",");
                        AnsiString Key2 = tList->Strings[i].SubString(1, ArrayPos-1);
                        AnsiString DeviceNum = tList->Strings[i].SubString(ArrayPos, tList->Strings[i].Length());

                        if(Key1 == Key2)
                        {
                                if(DeviceNum == 0)
                                {
                                        ;
                                }else{
                                        resultTemp += DeviceNum;
                                }
                                tList->Strings[i] = NULL;
                                //for(int j = i; j < cnt; j++)
                                //{
                                //        Array[j] = Array[j+1];
                                //}
                        }
                }else{
                        ;
                }
        }
}


이렇게 하면 리스트의 값들을 정렬 및 검색 할 수 있다.