Board index » delphi » Problem reading/writing all records in table

Problem reading/writing all records in table

I have three records in my test Table1.  The following code writes out record
one three times.  Even specifying Form2.Table1.Next does not write out eact
record one time.  

All help is much appreciated,
Stuart Kohler
<skoh...@aol.com>
----------------------------------

procedure TForm3.Button4Click(Sender: TObject);
begin
  PathStr := Application.ExeName;
  PathEnd := Pos('\TEST.EXE',PathStr);
  PathStr := Copy(PathStr,1,PathEnd);
  PathStr := PathStr + 'TEST.txt';

  System.Assign(Outputfile, PathStr);
  ReWrite(OutputFile);

  With Form2.Table1 DO
        Begin
          DisableControls;
        TRY
          First;
          WHILE NOT EOF DO
            Begin
              TestFile := Form2.DBEdit1.Text;
              Writeln(OutputFile, TestFile + '.');
              For N := 0 to Form2.DBMemo2.Lines.Count - 1 DO
                Writeln(OutputFile, '  ' + Form2.DBMemo2.Lines[N]);
              Writeln(OutputFile, '');
              For NN := 0 to Form2.DBMemo1.Lines.Count - 1 DO
                Writeln(OutputFile, Chr(9) + Form2.DBMemo1.Lines[NN]);
              Writeln(OutputFile, '');
              Writeln(OutputFile, '');
              Form2.Table1.Next;
            End;
        FINALLY
          CloseFile(OutputFile);
          EnableControls;
        End;
      End;
end;

 

Re:Problem reading/writing all records in table


Quote
SKOHLER wrote:

> I have three records in my test Table1.  The following code writes out record
> one three times.  Even specifying Form2.Table1.Next does not write out eact
> record one time.

> All help is much appreciated,
> Stuart Kohler
> <skoh...@aol.com>
> ----------------------------------

> procedure TForm3.Button4Click(Sender: TObject);
> begin
>   PathStr := Application.ExeName;
>   PathEnd := Pos('\TEST.EXE',PathStr);
>   PathStr := Copy(PathStr,1,PathEnd);
>   PathStr := PathStr + 'TEST.txt';

>   System.Assign(Outputfile, PathStr);
>   ReWrite(OutputFile);

>   With Form2.Table1 DO
>         Begin
>           DisableControls;
>         TRY
>           First;
>           WHILE NOT EOF DO
>             Begin
>               TestFile := Form2.DBEdit1.Text;
>               Writeln(OutputFile, TestFile + '.');
>               For N := 0 to Form2.DBMemo2.Lines.Count - 1 DO
>                 Writeln(OutputFile, '  ' + Form2.DBMemo2.Lines[N]);
>               Writeln(OutputFile, '');
>               For NN := 0 to Form2.DBMemo1.Lines.Count - 1 DO
>                 Writeln(OutputFile, Chr(9) + Form2.DBMemo1.Lines[NN]);
>               Writeln(OutputFile, '');
>               Writeln(OutputFile, '');
>               Form2.Table1.Next;
>             End;
>         FINALLY
>           CloseFile(OutputFile);
>           EnableControls;
>         End;
>       End;
> end;

Your code should work OK if you remove DisableControls / EnableControls
OR refer to the memofield itself, not the DBMemo control.

You could also (if you need the DisableControls) create an invisible
TMemo and assign the memofield into it: in your EOF-loop first clear the
lines, then assign ( Memo1.Lines.Assign( Table1MEMO_FIELD ); ) and print
these Memo1.Lines in a textfile.

--
Kari Heinonen / Veikko Heinonen Oy

http://personal.inet.fi/koti/veikko.heinonen/

Other Threads