Label com contagem de registros

04/06/2023

0

Pessoal, Estou usando um StringGrid para mandar registros para a tabela,gostaria de saber se alguém pode me ajudar a deixar em uma label com a quantidade de registros que está sendo importado do StringGrid para a tabela e a quantidade de registros q está na StringGrid,vamos supor que na StringGrid tenho 1000 registros, gostaria de deixar na label assim quando estou passando para a tabela em tempo de execução 10 de 1000
Sei que se colocar label1.caption := IntToStr(StringGrid.RowCount 0);
Ela conta a quantidade de registro que tem no StringGrid,mas preciso disso e de quantos registros está sendo passado para tabela em tempo de execução.
Alan

Alan

Responder

Post mais votado

05/06/2023

Se você está utilizando um StringGrid, imagino que vai varrer o grid e processar os dados, linha a linha.

  for row:=1 to Pred(SG.RowCount) do
    begin
      ... Processar os dados da linha "row"
      if ((row mod 10)=0) then
        begin
          label.Caption:=IntToStr(row)+' of '+IntToStr(Pred(SG.RowCount));
          label.Update;
        end;
    end;
    label.Caption:=IntToStr(Pred(SG.RowCount))+' of '+IntToStr(Pred(SG.RowCount));

Arthur Heinrich

Arthur Heinrich
Responder

Mais Posts

06/06/2023

Alan

Se você está utilizando um StringGrid, imagino que vai varrer o grid e processar os dados, linha a linha.

  for row:=1 to Pred(SG.RowCount) do
    begin
      ... Processar os dados da linha "row"
      if ((row mod 10)=0) then
        begin
          label.Caption:=IntToStr(row)+' of '+IntToStr(Pred(SG.RowCount));
          label.Update;
        end;
    end;
    label.Caption:=IntToStr(Pred(SG.RowCount))+' of '+IntToStr(Pred(SG.RowCount));



Amigo muito obrigado,e praticamente isso que eu queria, porém quando executo,a contagem fica meio desfocada,exemplo tenho 400 registros no StringGrid quando ele começa a processar os dados da linha ele vai do 0 ao 400 várias vezes seguidas até salvar tudo na tabela aí quando finaliza ele fica 400 de 400 certinho,mas quando está em execução ele vai do 0 ao 400 várias vezes muito rápido,sabe me dizer oq pode ser ?
Responder

06/06/2023

Arthur Heinrich

Se você está utilizando um StringGrid, imagino que vai varrer o grid e processar os dados, linha a linha.

  for row:=1 to Pred(SG.RowCount) do
    begin
      ... Processar os dados da linha "row"
      if ((row mod 10)=0) then
        begin
          label.Caption:=IntToStr(row)+' of '+IntToStr(Pred(SG.RowCount));
          label.Update;
        end;
    end;
    label.Caption:=IntToStr(Pred(SG.RowCount))+' of '+IntToStr(Pred(SG.RowCount));



Amigo muito obrigado,e praticamente isso que eu queria, porém quando executo,a contagem fica meio desfocada,exemplo tenho 400 registros no StringGrid quando ele começa a processar os dados da linha ele vai do 0 ao 400 várias vezes seguidas até salvar tudo na tabela aí quando finaliza ele fica 400 de 400 certinho,mas quando está em execução ele vai do 0 ao 400 várias vezes muito rápido,sabe me dizer oq pode ser ?


O exemplo que eu dei faz uma única varredura no StringGrid. Se você diz que a contagem vai de 0 a 400 várias vezes, é sinal de que sua rotina está sendo executada múltiplas vezes.

Precisa descobrir como a rotina é chamada, para entender o que pode estar executando o loop múltiplas vezes.
Responder

06/06/2023

Alan

Se você está utilizando um StringGrid, imagino que vai varrer o grid e processar os dados, linha a linha.

  for row:=1 to Pred(SG.RowCount) do
    begin
      ... Processar os dados da linha "row"
      if ((row mod 10)=0) then
        begin
          label.Caption:=IntToStr(row)+' of '+IntToStr(Pred(SG.RowCount));
          label.Update;
        end;
    end;
    label.Caption:=IntToStr(Pred(SG.RowCount))+' of '+IntToStr(Pred(SG.RowCount));



Amigo muito obrigado,e praticamente isso que eu queria, porém quando executo,a contagem fica meio desfocada,exemplo tenho 400 registros no StringGrid quando ele começa a processar os dados da linha ele vai do 0 ao 400 várias vezes seguidas até salvar tudo na tabela aí quando finaliza ele fica 400 de 400 certinho,mas quando está em execução ele vai do 0 ao 400 várias vezes muito rápido,sabe me dizer oq pode ser ?


O exemplo que eu dei faz uma única varredura no StringGrid. Se você diz que a contagem vai de 0 a 400 várias vezes, é sinal de que sua rotina está sendo executada múltiplas vezes.

Precisa descobrir como a rotina é chamada, para entender o que pode estar executando o loop múltiplas vezes.


Meu codigo esta sendo executado assim,sou iniciante na programação,se puder me dar uma ajuda com essa questão te agradeço muito.

procedure TFrmImportacao.BtnImportDadosClick(Sender: TObject);
Var I : integer;
Row : Integer;
begin
if LkSetor.text = '' then
begin
ShowMessage('Selecione o setor!');
LkSetor.SetFocus;
exit;
end;
begin
if Application.MessageBox('Deseja importar dados da aba selecionada para esse setor?','Atenção',MB_ICONQUESTION+MB_YESNO) =mrYes then
Gauge1.Max := AdvGridWorkbook1.Grid.RowCount;
Gauge1.Position := 1;

for I := 1 to Pred( AdvGridWorkbook1.Grid.RowCount) do
begin
Application.ProcessMessages;
Gauge1.Position := Gauge1.Position + 1 ;
IngressosTable.Append;

if CbHex.Checked = True then
begin

IngressosTableIdentificacao_hex.Value := AdvGridWorkbook1.Grid.Cells[1, i];
IngressosTableIdentificacao.Value := Unassigned;
end
else
begin

IngressosTableIdentificacao.Value := AdvGridWorkbook1.Grid.Cells[1, i];
end;

IngressosTableNome.Value := AdvGridWorkbook1.Grid.Cells[2, i];
IngressosTableSetor.Value := AdvGridWorkbook1.Grid.Cells[3, i];
IngressosTableId_setor.Value := LkSetor.KeyValue;

IngressosTable.post;

begin
for row := 1 to pred (AdvGridWorkbook1.Grid.RowCount ) do
begin
if row mod 10 = 0 then
begin

label2.Caption:=IntToStr(row)+' de '+IntToStr(Pred(AdvGridWorkbook1.Grid.RowCount));
label2.Update;
end;
end;

label2.Caption:= IntToStr(Pred(AdvGridWorkbook1.Grid.RowCount ))+' de '+IntToStr(Pred(AdvGridWorkbook1.Grid.RowCount));
end;
end;
ShowMessage('Importado com Sucesso');
AdvGridWorkbook1.RemoveSheet(AdvGridWorkbook1.ActiveSheet);
end;
end;
Responder

07/06/2023

Arthur Heinrich

Se você está utilizando um StringGrid, imagino que vai varrer o grid e processar os dados, linha a linha.

  for row:=1 to Pred(SG.RowCount) do
    begin
      ... Processar os dados da linha "row"
      if ((row mod 10)=0) then
        begin
          label.Caption:=IntToStr(row)+' of '+IntToStr(Pred(SG.RowCount));
          label.Update;
        end;
    end;
    label.Caption:=IntToStr(Pred(SG.RowCount))+' of '+IntToStr(Pred(SG.RowCount));



Amigo muito obrigado,e praticamente isso que eu queria, porém quando executo,a contagem fica meio desfocada,exemplo tenho 400 registros no StringGrid quando ele começa a processar os dados da linha ele vai do 0 ao 400 várias vezes seguidas até salvar tudo na tabela aí quando finaliza ele fica 400 de 400 certinho,mas quando está em execução ele vai do 0 ao 400 várias vezes muito rápido,sabe me dizer oq pode ser ?


O exemplo que eu dei faz uma única varredura no StringGrid. Se você diz que a contagem vai de 0 a 400 várias vezes, é sinal de que sua rotina está sendo executada múltiplas vezes.

Precisa descobrir como a rotina é chamada, para entender o que pode estar executando o loop múltiplas vezes.


Meu codigo esta sendo executado assim,sou iniciante na programação,se puder me dar uma ajuda com essa questão te agradeço muito.

procedure TFrmImportacao.BtnImportDadosClick(Sender: TObject);
Var I : integer;
Row : Integer;
begin
if LkSetor.text = '' then
begin
ShowMessage('Selecione o setor!');
LkSetor.SetFocus;
exit;
end;
begin
if Application.MessageBox('Deseja importar dados da aba selecionada para esse setor?','Atenção',MB_ICONQUESTION+MB_YESNO) =mrYes then
Gauge1.Max := AdvGridWorkbook1.Grid.RowCount;
Gauge1.Position := 1;

for I := 1 to Pred( AdvGridWorkbook1.Grid.RowCount) do
begin
Application.ProcessMessages;
Gauge1.Position := Gauge1.Position + 1 ;
IngressosTable.Append;

if CbHex.Checked = True then
begin

IngressosTableIdentificacao_hex.Value := AdvGridWorkbook1.Grid.Cells[1, i];
IngressosTableIdentificacao.Value := Unassigned;
end
else
begin

IngressosTableIdentificacao.Value := AdvGridWorkbook1.Grid.Cells[1, i];
end;

IngressosTableNome.Value := AdvGridWorkbook1.Grid.Cells[2, i];
IngressosTableSetor.Value := AdvGridWorkbook1.Grid.Cells[3, i];
IngressosTableId_setor.Value := LkSetor.KeyValue;

IngressosTable.post;

begin
for row := 1 to pred (AdvGridWorkbook1.Grid.RowCount ) do
begin
if row mod 10 = 0 then
begin

label2.Caption:=IntToStr(row)+' de '+IntToStr(Pred(AdvGridWorkbook1.Grid.RowCount));
label2.Update;
end;
end;

label2.Caption:= IntToStr(Pred(AdvGridWorkbook1.Grid.RowCount ))+' de '+IntToStr(Pred(AdvGridWorkbook1.Grid.RowCount));
end;
end;
ShowMessage('Importado com Sucesso');
AdvGridWorkbook1.RemoveSheet(AdvGridWorkbook1.ActiveSheet);
end;
end;


Você colocou um loop dentro do outro. Por isso, para cada linha do loop externo, repetiu o loop interno.

Acho que deveria ficar mais ou menos assim:

procedure TFrmImportacao.BtnImportDadosClick(Sender: TObject);
var
  I : integer;
  Row : Integer;
begin
  if LkSetor.text = '' then
    begin
      ShowMessage('Selecione o setor!');
      LkSetor.SetFocus;
      exit;
    end;
  if Application.MessageBox('Deseja importar dados da aba selecionada para esse setor?','Atenção',MB_ICONQUESTION+MB_YESNO) =mrYes then
    begin
      Gauge1.Max := Pred(AdvGridWorkbook1.Grid.RowCount);
      Gauge1.Position := 0;

      for I := 1 to Pred( AdvGridWorkbook1.Grid.RowCount) do
        begin
          Application.ProcessMessages;
          IngressosTable.Append;

          if CbHex.Checked then
            begin
              IngressosTableIdentificacao_hex.Value := AdvGridWorkbook1.Grid.Cells[1, i];
              IngressosTableIdentificacao.Value := Unassigned;
            end
          else
            begin
              IngressosTableIdentificacao.Value := AdvGridWorkbook1.Grid.Cells[1, i];
            end;

          IngressosTableNome.Value := AdvGridWorkbook1.Grid.Cells[2, i];
          IngressosTableSetor.Value := AdvGridWorkbook1.Grid.Cells[3, i];
          IngressosTableId_setor.Value := LkSetor.KeyValue;

          IngressosTable.post;

          Gauge1.Position := I;
          label2.Caption:=IntToStr(I)+' de '+IntToStr(Pred(AdvGridWorkbook1.Grid.RowCount));
        end;
      ShowMessage('Importado com Sucesso');
      AdvGridWorkbook1.RemoveSheet(AdvGridWorkbook1.ActiveSheet);
    end;
end;

Responder

08/06/2023

Alan

Se você está utilizando um StringGrid, imagino que vai varrer o grid e processar os dados, linha a linha.

  for row:=1 to Pred(SG.RowCount) do
    begin
      ... Processar os dados da linha "row"
      if ((row mod 10)=0) then
        begin
          label.Caption:=IntToStr(row)+' of '+IntToStr(Pred(SG.RowCount));
          label.Update;
        end;
    end;
    label.Caption:=IntToStr(Pred(SG.RowCount))+' of '+IntToStr(Pred(SG.RowCount));



Amigo muito obrigado,e praticamente isso que eu queria, porém quando executo,a contagem fica meio desfocada,exemplo tenho 400 registros no StringGrid quando ele começa a processar os dados da linha ele vai do 0 ao 400 várias vezes seguidas até salvar tudo na tabela aí quando finaliza ele fica 400 de 400 certinho,mas quando está em execução ele vai do 0 ao 400 várias vezes muito rápido,sabe me dizer oq pode ser ?


O exemplo que eu dei faz uma única varredura no StringGrid. Se você diz que a contagem vai de 0 a 400 várias vezes, é sinal de que sua rotina está sendo executada múltiplas vezes.

Precisa descobrir como a rotina é chamada, para entender o que pode estar executando o loop múltiplas vezes.


Meu codigo esta sendo executado assim,sou iniciante na programação,se puder me dar uma ajuda com essa questão te agradeço muito.

procedure TFrmImportacao.BtnImportDadosClick(Sender: TObject);
Var I : integer;
Row : Integer;
begin
if LkSetor.text = '' then
begin
ShowMessage('Selecione o setor!');
LkSetor.SetFocus;
exit;
end;
begin
if Application.MessageBox('Deseja importar dados da aba selecionada para esse setor?','Atenção',MB_ICONQUESTION+MB_YESNO) =mrYes then
Gauge1.Max := AdvGridWorkbook1.Grid.RowCount;
Gauge1.Position := 1;

for I := 1 to Pred( AdvGridWorkbook1.Grid.RowCount) do
begin
Application.ProcessMessages;
Gauge1.Position := Gauge1.Position + 1 ;
IngressosTable.Append;

if CbHex.Checked = True then
begin

IngressosTableIdentificacao_hex.Value := AdvGridWorkbook1.Grid.Cells[1, i];
IngressosTableIdentificacao.Value := Unassigned;
end
else
begin

IngressosTableIdentificacao.Value := AdvGridWorkbook1.Grid.Cells[1, i];
end;

IngressosTableNome.Value := AdvGridWorkbook1.Grid.Cells[2, i];
IngressosTableSetor.Value := AdvGridWorkbook1.Grid.Cells[3, i];
IngressosTableId_setor.Value := LkSetor.KeyValue;

IngressosTable.post;

begin
for row := 1 to pred (AdvGridWorkbook1.Grid.RowCount ) do
begin
if row mod 10 = 0 then
begin

label2.Caption:=IntToStr(row)+' de '+IntToStr(Pred(AdvGridWorkbook1.Grid.RowCount));
label2.Update;
end;
end;

label2.Caption:= IntToStr(Pred(AdvGridWorkbook1.Grid.RowCount ))+' de '+IntToStr(Pred(AdvGridWorkbook1.Grid.RowCount));
end;
end;
ShowMessage('Importado com Sucesso');
AdvGridWorkbook1.RemoveSheet(AdvGridWorkbook1.ActiveSheet);
end;
end;


Você colocou um loop dentro do outro. Por isso, para cada linha do loop externo, repetiu o loop interno.

Acho que deveria ficar mais ou menos assim:

procedure TFrmImportacao.BtnImportDadosClick(Sender: TObject);
var
  I : integer;
  Row : Integer;
begin
  if LkSetor.text = '' then
    begin
      ShowMessage('Selecione o setor!');
      LkSetor.SetFocus;
      exit;
    end;
  if Application.MessageBox('Deseja importar dados da aba selecionada para esse setor?','Atenção',MB_ICONQUESTION+MB_YESNO) =mrYes then
    begin
      Gauge1.Max := Pred(AdvGridWorkbook1.Grid.RowCount);
      Gauge1.Position := 0;

      for I := 1 to Pred( AdvGridWorkbook1.Grid.RowCount) do
        begin
          Application.ProcessMessages;
          IngressosTable.Append;

          if CbHex.Checked then
            begin
              IngressosTableIdentificacao_hex.Value := AdvGridWorkbook1.Grid.Cells[1, i];
              IngressosTableIdentificacao.Value := Unassigned;
            end
          else
            begin
              IngressosTableIdentificacao.Value := AdvGridWorkbook1.Grid.Cells[1, i];
            end;

          IngressosTableNome.Value := AdvGridWorkbook1.Grid.Cells[2, i];
          IngressosTableSetor.Value := AdvGridWorkbook1.Grid.Cells[3, i];
          IngressosTableId_setor.Value := LkSetor.KeyValue;

          IngressosTable.post;

          Gauge1.Position := I;
          label2.Caption:=IntToStr(I)+' de '+IntToStr(Pred(AdvGridWorkbook1.Grid.RowCount));
        end;
      ShowMessage('Importado com Sucesso');
      AdvGridWorkbook1.RemoveSheet(AdvGridWorkbook1.ActiveSheet);
    end;
end;




Amigo Muito Obrigado mais uma vez, agora deu certo, Deus Abençoe você.
Responder

Assista grátis a nossa aula inaugural

Assitir aula

Saiba por que programar é uma questão de
sobrevivência e como aprender sem riscos

Assistir agora

Utilizamos cookies para fornecer uma melhor experiência para nossos usuários, consulte nossa política de privacidade.

Aceitar