Recent

Author Topic: problems with the use of writeln  (Read 2821 times)

frederic

  • Full Member
  • ***
  • Posts: 226
problems with the use of writeln
« on: August 13, 2015, 05:43:17 pm »
in an other thread on this forum i was invited to use writeln  calls to look for abnormal values in the code.

 writeln is not used by me up till now ; i am used to memo for these cases;

the problem is when i use the writeln in loops and i look back at the result ,a lot of times(unfornutaly not always) the text stops in de middle of a line  .(with a file of appr 4000 lines 3 lines before the end);

i use following:
Code: [Select]
var
  Form1: TForm1;
   testtextfile, followtesttextfile: Text; }
    ''''''
    ''''

  procedure TForm1.FormCreate(Sender: TObject);
  begin
  Assignfile(testtextfile,'feedunittest');
  ReWrite(testtextfile);
   end;

  procedure Tform1.XXXXX ;
var mmm:integer;
     begin
     for mmm:=0 to 4000 do
     begin
    // FDTXAxarr1   FXaxdayspassed1 are dynamic arrays
     WriteLn(testtextfile, 'FDTXAxarr1['+inttostr(mmm)+']= '+ datetimetostr(FDTXAxarr1[mmm])+ ';'+floattostr(FXaxdayspassed1[mmm]));
     end;

    procedure TForm1.FormClose(Sender: TObject; var CloseAction: TCloseAction);
   begin
   CloseFile(testtextfile);
    end;

               

did i forget something??

frederic

rvk

  • Hero Member
  • *****
  • Posts: 7063
Re: problems with the use of writeln
« Reply #1 on: August 13, 2015, 06:18:00 pm »
You could try Flush(testtextfile); before closing the file but that shouldn't be necessary.

derek.john.evans

  • Guest
Re: problems with the use of writeln
« Reply #2 on: August 13, 2015, 07:01:30 pm »
Maybe TForm1.FormClose() has become disconnected from the TForm. ie: You might have deleted FormClose from the object inspector.

Either way, you should open/close the file in the same function. That way you ensure the file is completely written out.
« Last Edit: August 13, 2015, 07:16:11 pm by derek.john.evans »

kpeters58

  • Sr. Member
  • ****
  • Posts: 267
Re: problems with the use of writeln
« Reply #3 on: August 13, 2015, 07:06:24 pm »
Not sure if this could be a form of range check issue? You could turn Range Checking on and see.

Either way, I always do something along the lines of the code below for such purposes:

Code: [Select]
procedure Tform1.XXXXX;
var
  sl: TStringList;
  mm: Integer;

begin
  sl := TStringList.Create;
  try
    for mmm := 0 to 4000 do
      sl.Add('FDTXAxarr1[' + IntToStr(mmm) + '] = ' + FormatDateTime('yyyy-mm-dd', FDTXAxarr1[mmm]) + ';' + FloatToStr(FXaxdayspassed1[mmm]));
    //
    sl.SaveToFile('feedunittest');
  finally
    if Assigned(sl) then
      sl.Free;
end;
Lazarus 2.0.4/FPC 3.0.4/Win 64

frederic

  • Full Member
  • ***
  • Posts: 226
Re: problems with the use of writeln
« Reply #4 on: August 13, 2015, 09:27:22 pm »
Thanks for your reactions,

1. rvk    flush(testtextfile) before closefile(testtextfile ) in the formclose did't improve the situation.

Wat i didn't mention before is, that just before writeln is used in the loop ,a memo is filled with the same string and that is complete and oke.
I did 3 test with the flush : 

FDTXAxarr1[2543]= 21-11-2014 17:28:00;4,99607843137255
FDTXAxarr1[254 

FDTXAxarr1[3053]= 24-11-2014 17:29:00;5,99803921568627
LAST on DAy FDTXAxarr1[3054]= 24-   

FDTXAxarr1[8651]= 9-12-2014 17:28:00;16,9960784313725
FDTXAxarr1[8652]= 9-12-2014 17:29:00;16,9980392156863
LAST on     

2. derek
indeed by assigning and closing the file in the xxxx- procedure the whole file is listed by writeln

3 . kpeters   :the range of the dynamic arrays was set very ample

so the issue is solved although it makes me think why

thanks again

frederic

 

TinyPortal © 2005-2018