Import data from a TXT and play required positions in Stringgrid

Asked

Viewed 1,523 times

0

Follow the code 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 just to show the lines I rescued from TXT to inform on TStringGrid.

What would I be missing there?

  • What error has arisen?

  • [dcc32 Error] Uni3.pas(55): E2149 Class does not have a default Property

1 answer

1


Let’s go in pieces:

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

According to, the syntax of the command copy(arq[c][l],1,3);, if I got it right, it’s wrong. It should be copy(Arq.Cells[c,l],1,3);

Third, you’re not doing anything with the TStringGrid. Neither populating nor using its data. The copy command created by you is not assigned to anything or anyone.

Quarter, the error reported in the comment has nothing to do with the posted Procedure (which by itself would not compile for other reasons). The error quoted is probably elsewhere in Unit.

Finally, follow the corrected process:

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;
  • Thank you very much, I haven’t finished the code, but it’s almost finished. Thank you @Filipe.Fonseca

  • 2

    I did the following by replacing the bold item with "sgCupons.Cells[0,l] := copy(lTemp,47,6);"

  • @DBX8 if your edit made the post exactly as it was in the beginning, it would no longer be interesting to revert to version 1?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.