Q&A

  • 루프문이 계속 빠지지 않고 돌아가는데 왜 그런지 잘 모르겠습니다..
루프문이 계속 빠지지 않고 돌아가는데 왜 그런지 잘 모르겠습니다.

알려주세요...



startcount에 10을 넣고 endcount에 20을 넣고 돌리면 계속 돌거든요.....





procedure TForm1.PrinterClick(Sender: TObject);

begin

AssignFile(filename, 'c:/text/data.txt');

Reset(filename);

i :=0;

// with Printer do begin

AssignFile(outFile, 'c:/지로/text.txt');

ReWrite(outFile);

startcount := strtoint(Edit1.text);

endcount := strtoint(Edit2.text);



While Not Eof(filename) Do Begin <== 이부분이 계속 도네요..알려주세요...

// if sss = Eof(filename) then

// exit;



while i < 9999999 do begin

ReadLn(filename, MyStr);



if Eof(filename) then

exit;



i := i+1;

if (i >= startcount) and (i <= endcount) then

WriteData

else if i > endcount then

i:=9999999;

end;



end;

CloseFile(filename);

CloseFile(outFile);

end;

2  COMMENTS
  • Profile
    지나는 이 2001.10.20 12:51
    이쁜이 wrote:

    > 루프문이 계속 빠지지 않고 돌아가는데 왜 그런지 잘 모르겠습니다.

    > 알려주세요...

    >

    > startcount에 10을 넣고 endcount에 20을 넣고 돌리면 계속 돌거든요.....

    >

    >

    > procedure TForm1.PrinterClick(Sender: TObject);

    > begin

    > AssignFile(filename, 'c:/text/data.txt');

    > Reset(filename);

    > i :=0;

    > // with Printer do begin

    > AssignFile(outFile, 'c:/지로/text.txt');

    > ReWrite(outFile);

    > startcount := strtoint(Edit1.text);

    > endcount := strtoint(Edit2.text);

    >

    > While Not Eof(filename) Do Begin <== 이부분이 계속 도네요..알려주세요...

    > // if sss = Eof(filename) then

    > // exit;

    >

    > while i < 9999999 do begin

    > ReadLn(filename, MyStr);

    >

    > if Eof(filename) then

    > exit;

    >

    > i := i+1;

    > if (i >= startcount) and (i <= endcount) then

    > WriteData

    > else if i > endcount then

    > i:=9999999;

    > end;

    >

    > end;

    > CloseFile(filename);

    > CloseFile(outFile);

    > end;



    일단 코딩내용을 주석으루 막구 폼을 생성후 닫아 보세요.

    그래서 닫아 지면 밑의 방법으루 테스트 해보시구 안되면

    폼을 새루 만들어서 코딩을 해보세요.



    일단 Timer를 하나 만드세요.

    다음에 FormCreate에 한 코딩을 Timer의 OnTimer Event로 옮기시고,



    FormCreate에

    Timer.Enabled := True ;



    Timer의 OnTimer Event에

    Timer.Enabled := False ;

    //=====================

    해당 코딩 ...



    글구 코딩내용중 성공하나 실패하는 폼은 닫는 거 같으니

    SendMessage 없애구 대신 맨 밑에 Close 를...



    글구 FormClose의 Close는 없애시구, 만약 MDI Child 같으면,

    FormClose에 Action := caFree 를 넣으시구요..



    이러면 대충될 거 같은디요..

    머리속으로 만 돌려서 어떨지 모르겠네....



    오빠가... (^^;)



  • Profile
    지나가는사람 2001.10.19 20:39
    로직상 무한루프가 될 가능성이 있네요..



    While (Not Eof(filename)) and (I < 9999999) Do Begin





    이쁜이 wrote:

    > 루프문이 계속 빠지지 않고 돌아가는데 왜 그런지 잘 모르겠습니다.

    > 알려주세요...

    >

    > startcount에 10을 넣고 endcount에 20을 넣고 돌리면 계속 돌거든요.....

    >

    >

    > procedure TForm1.PrinterClick(Sender: TObject);

    > begin

    > AssignFile(filename, 'c:/text/data.txt');

    > Reset(filename);

    > i :=0;

    > // with Printer do begin

    > AssignFile(outFile, 'c:/지로/text.txt');

    > ReWrite(outFile);

    > startcount := strtoint(Edit1.text);

    > endcount := strtoint(Edit2.text);

    >

    > While Not Eof(filename) Do Begin <== 이부분이 계속 도네요..알려주세요...

    > // if sss = Eof(filename) then

    > // exit;

    >

    > while i < 9999999 do begin

    > ReadLn(filename, MyStr);

    >

    > if Eof(filename) then

    > exit;

    >

    > i := i+1;

    > if (i >= startcount) and (i <= endcount) then

    > WriteData

    > else if i > endcount then

    > i:=9999999;

    > end;

    >

    > end;

    > CloseFile(filename);

    > CloseFile(outFile);

    > end;