|
아래 김백일님의 친절한 설명으로 라인단위로 읽는
것은 성공(?) 했습니다.
그런데... 라인에서 특정 스트링을 검색하는 것은
실패...
그래서 다시 문의 드립니다.
//-------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include <iostream.h>
#include "Unit1.h"
//-------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//--------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
Label1->Caption = AnsiString("현재시간 : ")
+ TimeToStr(Time());
}
//---------------------------------------------
/* 5분마다 list.txt 파일을 열어서 list_new.txt 파
일을 생성하는 모듈 ListBox1 및 ListBox2에 출력하는
이유는 이것 저것 해보느라고 쓴것이고 큰 의미는 없습
니다. */
void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
Timer1->Interval = 300000;
int i;
TStringList *MyList = new TStringList();
MyList->LoadFromFile("list.txt");
ListBox1->Items->Clear();
for (i=0; i < MyList->Count; i++) {
ListBox1->Items->Add(MyList->Strings[i]);
ListBox2->Items->Add(MyList->Strings[i]);
}
MyList->SaveToFile("list_new.txt");
delete MyList;
}
//------------------------------------------------
/* 문제는 요놈인데...
아래 "// ListBox1->Items->Add(MyList->Strings[j]);"
인데 이걸 주석으로 처리하지 않고 실행시키면 컴파일/링크
는 정상적으로 되는데 실행하여 버튼을 클릭하면, 에러 메
시지가 발생합니다(추가로 MyList를 TempList라는 이름으
로 바꿔도 안되네요..)
Project Porject1.ext raised exception class
EStringListError with message 'List index out of
bounds(-16709743)'. Process stopped. Use Step or
Run to continue.
계속 진행하면, "List index out of bounds(-16709743)"
라는 메시지가 뜹니다
왜, 에러 메시지가 뜨는지 궁굼합니다.
또한, 주석처리를 하고 실행하면 ListBox2에는 "SYS_FIRE"
라는 스트링을 가진 라인이 출력되어야 할것 같은데 이것도
안됩니다. */
void __fastcall TForm1::Button1Click(TObject *Sender)
{
int j;
TStringList *MyList = new TStringList();
MyList->LoadFromFile("list.txt");
// ListBox1->Items->Add(MyList->Strings[j]);
ListBox2->Items->Clear();
for (j=0; j < MyList->Count; j++)
if (MyList->Find("SYS_FIRE",j))
ListBox2->Items->Add(MyList->Strings[j]);
delete MyList;
}
|