procedure TForm1.Button1Click(Sender: TObject);
begin
for n := 24755 to 30000 do
begin
count := count + 1;
name := 'AR'+Inttostr(n);
genre := 'rock';
isband := 'B';
{//////////////////날짜발생 루틴/////////////////////////}
year1 := random(6)+3;
year2 := random(9);
month := random(11)+1;
day := random(29)+1;
born := '19'+inttostr(year1)+inttostr(year2);
if month < 10 then
born := born+'0'+inttostr(month)
else
born := born+inttostr(month);
if day < 10 then
born := born+'0'+inttostr(day)
else
born := born+inttostr(day);
{/////////////////////////////////////////////////////////}
{///////////////////txt 생성루틴//////////////////////////}
StrL := TStringList.Create;
StrL.LoadfromFile('c:dbhwdataartist.txt');
StrL.Insert(n,inttostr(n)+','+name+','+born+','+genre+','+isband);
StrL.SaveToFile('c:dbhwdataartist.txt');
if count = 100 then
begin
StrL.Free;
count := 0;
end;
{/////////////////////////////////////////////////////////}
progressbar1.Position := n;
end;
StrL.Free;
showmessage('입력이 모두 끝났습니다.');
end;
다음과 같은 코딩이 들어간 상태에서 실행을 시키면 약 1000개의 값(라인)이 들어간뒤
Out of Memory 에러가 나버립니다...그래서 StrL.Free를 for 문 안에 집어넣으면
아에 프로세스가 중단되 버리고요....뭐 좋은 방법 없을까요....부탁드립니다...
> {///////////////////txt 생성루틴//////////////////////////}
> StrL := TStringList.Create;
> StrL.LoadfromFile('c:dbhwdataartist.txt');
> StrL.Insert(n,inttostr(n)+','+name+','+born+','+genre+','+isband);
> StrL.SaveToFile('c:dbhwdataartist.txt');
> if count = 100 then
> begin
> StrL.Free;
> count := 0;
> end;
> {/////////////////////////////////////////////////////////}
> progressbar1.Position := n;
> end;
> StrL.Free;
> showmessage('입력이 모두 끝났습니다.');
> end;
님아? 위 문장에서 StrL 이 count 가 100 일때만 Free 되게 되어 있네요?
생각해보세요.
StrL := TStringList.Create; 이 문장은
count 가 100 이 아닐때도 for 문장안에서 한번씩 계속해서 실행됩니다.
그러면 생성을 무쟈게 해내겠지요.
그러나 해제는 count 가 100일때만 하니까 Free는 100 에 한번만
되는 코드가 되어 있네요. ^_^
그 부분이 아래처럼 수정되어야 할거 같네요.
StrL := TStringList.Create;
try
StrL.LoadfromFile('c:dbhwdataartist.txt');
StrL.Insert(n,inttostr(n)+','+name+','+born+','+genre+','+isband);
StrL.SaveToFile('c:dbhwdataartist.txt');
finally
StrL.Free;
end;
그럼~~ 항상 즐거운 프로그래밍 하시구요~~