Import data from a TXT and play the required positions in the StringGrid

0

Follow the code that I developed along with my co-worker.

    procedure TfrmGrid.Button1Click(Sender: TObject);
    var
      arq: TStringGrid;
      txt: TextFile;
      c, l, treg : integer;
      lTemp: String;
    begin
      treg := 0;
      c:=0;
      l:=0;
      AssignFile(txt, Label1.Caption);
      Reset(txt);
      while not eof(txt) do
        begin
          Readln(txt, lTemp);
          if (copy(lTemp, 1, 3) = 'E14') or (copy(ltemp, 1, 3) = 'E15') then
            inc(treg);
        end;
      while not eof(txt) do
        begin
          Readln(txt, lTemp);
          if (copy(lTemp, 1, 3)= 'E14') then
          c:= c+1;
          copy(arq[c][l],1,3);
        end;
      CloseFile(txt);

      ShowMessage('total de linhas: '+IntToStr(treg));
    end;

What I need is only to show the lines that I rescued from TXT to report on TStringGrid .

What would I be missing there?

    
asked by anonymous 06.05.2014 / 20:17

1 answer

1

Let's break it down:

First , you do not create TStringGrid at run time. Create the component in design time.

Second , the syntax of the copy(arq[c][l],1,3); command, if I understand correctly, is wrong. It should be copy(Arq.Cells[c,l],1,3);

Third , you are not doing anything with TStringGrid . Neither populating nor using his data. The copy command you created is not assigned to anything or anyone.

Room , the error reported in the comment has nothing to do with the procedure (which would not compile for other reasons) posted. The above error is probably elsewhere in the unit.

Finishing, follow corrected procedure:

procedure TForm1.Button1Click(Sender: TObject);
var
  txt: TextFile;
  c, l, treg : integer;
  lTemp: String;
begin
  treg := 0;
  c:=0;
  l:=1;
  AssignFile(txt, 'c:\teste.txt');
  Reset(txt);
  while not eof(txt) do
  begin
    Readln(txt, lTemp);
    if (copy(lTemp, 1, 3) = 'E14') or (copy(ltemp, 1, 3) = 'E15') then
      inc(treg);
  end;
  while not eof(txt) do
  begin
    Readln(txt, lTemp);
    if (copy(lTemp, 1, 3)= 'E14') then
      c:= c+1;
    copy(Arq.Cells[c,l],1,3); //??
  end;
  CloseFile(txt);
  ShowMessage('total de linhas: '+IntToStr(treg));
end;
    
06.05.2014 / 20:41