Ir para conteúdo
Fórum Script Brasil
  • 0

Locate localizando o próximo do locate se houver


LucAlucard

Pergunta

Oi gente alguém sabe como dar um locate em uma tabela localizando o próximo carinha do meu locate? (parece confuso né mas é mais simples do que parece...) por exemplo:

Imaginem um locate simples como o exemplo a direita (-->): locate('A'.TABELA.FieldByName('CAMPO').AsString,[loPartialKey])

E uma tabela onde tenho os registros gravados nela e onde o registro vermelho é onde o meu locate se encontra:

ALBERTO

ARMANDO

ALDEMIR

BRUNO

BRENO

CACÁ

Porém isso é simples... mas como dar um "Locate Next"? Por exemplo eu dei aquele locate a cima não foi? eu quero que quando eu der meu outro locate (ou apertar novamente o botão de localizar) ele localize o próximo registro se ouver no caso o ARMANDO. Ficando assim:

ALBERTO

ARMANDO

ALDEMIR

BRUNO

BRENO

CACÁ

Des de já agradeço a ajuda de todos.. Se eu não fui claro suficiênte por favor perguntem q eu tento responder. Vlw a ajuda mesmo gente! Flws

Link para o comentário
Compartilhar em outros sites

7 respostass a esta questão

Posts Recomendados

  • 0

Ordene a sua tabela alfabeticamente, e depois de o locate 'A' por exemplo.... ele irá encontrar o primeiro 'A' da lista... para os proximos basta dar next na tabela

Outros exemplos:

http://www.componentace.com/search-records-delphi.htm

http://www.edudelphipage.com.br/dicas_text...ia=3&busca=

abraço

Link para o comentário
Compartilhar em outros sites

  • 0
então se ele estiver ordenado ele vai fazer isso automaticamente?
sim ... mas lembre que após cada next, voce deve testar o inicio do proximo registro para saber que chegou ao fim a pesquisa

ALBERTO

ARMANDO

ALDEMIR

----------- // a pesquisa deve encerrar aqui

BRUNO

BRENO

mas e se ele não tiver ordenado não vai funcionar?

se não estiver ordenado, o ponteiro do locate irá para sempre no primeiro registro da ocorrencia

abraço

Link para o comentário
Compartilhar em outros sites

  • 0
Não existe um locate Next ou alguma coisa desse tipo?

voce pode usar o FindNext

Implements a virtual method for positioning the cursor to the next record in a filtered dataset.

function FindNext: Boolean;

Description

This function returns False, indicating that the cursor was not successfully repositioned. Descendant classes override FindNext to position the cursor to the next record of the dataset, honoring any filters that are in effect. FindNext should return True if the cursor is successfully repositioned.

exemplo:

procedure TForm1.Button1Click(Sender: TObject);

var
  sr: TSearchRec;
  FileAttrs: Integer;
begin
  StringGrid1.RowCount := 1;
  if CheckBox1.Checked then
    FileAttrs := faReadOnly
  else
    FileAttrs := 0;
  if CheckBox2.Checked then
    FileAttrs := FileAttrs + faHidden;
  if CheckBox3.Checked then
    FileAttrs := FileAttrs + faSysFile;
  if CheckBox4.Checked then
    FileAttrs := FileAttrs + faVolumeID;
  if CheckBox5.Checked then

    FileAttrs := FileAttrs + faDirectory;
  if CheckBox6.Checked then
    FileAttrs := FileAttrs + faArchive;
  if CheckBox7.Checked then

    FileAttrs := FileAttrs + faAnyFile;

  if FindFirst(Edit1.Text, FileAttrs, sr) = 0 then

  begin
    with StringGrid1 do
    begin
      if (sr.Attr and FileAttrs) = sr.Attr then
      begin
        Cells[1,RowCount-1] := sr.Name;
        Cells[2,RowCount-1] := IntToStr(sr.Size);
      end;
      while FindNext(sr) = 0 do
      begin
        if (sr.Attr and FileAttrs) = sr.Attr then
        begin
        RowCount := RowCount + 1;
        Cells[1, RowCount-1] := sr.Name;

        Cells[2, RowCount-1] := IntToStr(sr.Size);
        end;
      end;
      FindClose(sr);
    end;
  end;
end;
outra solução: Um botão para pesquisar com o código
ClientDataSet.FindKey([EditBusca.Text]);
E outro botão procurar o proximo
ClientDataSet.FindNext;
outra solução: uses IBCustomDataSet; Código:
TIBCustomDataSet(Datasource.dataset).LocateNext('','',[]);
outra solução:
DM.qrProduPesq.Close;
      DM.qrProduPesq.SQL.Clear;
      DM.qrProduPesq.SQL.Add('SELECT nome, codigo FROM PRODU WHERE UPPER(nome) LIKE ' + #39 + '%' + Edit1.Text + '%' + #39);
      DM.qrProduPesq.Open;

usando Like na sentença sql voce traz somente os registros que satisfaçam as condições

abraço

Link para o comentário
Compartilhar em outros sites

  • 0

Cara você pode me explicar o seu 1º código?

procedure TForm1.Button1Click(Sender: TObject);

var
  sr: TSearchRec;
  FileAttrs: Integer;
begin
  StringGrid1.RowCount := 1;
  if CheckBox1.Checked then
    FileAttrs := faReadOnly
  else
    FileAttrs := 0;
  if CheckBox2.Checked then
    FileAttrs := FileAttrs + faHidden;
  if CheckBox3.Checked then
    FileAttrs := FileAttrs + faSysFile;
  if CheckBox4.Checked then
    FileAttrs := FileAttrs + faVolumeID;
  if CheckBox5.Checked then

    FileAttrs := FileAttrs + faDirectory;
  if CheckBox6.Checked then
    FileAttrs := FileAttrs + faArchive;
  if CheckBox7.Checked then

    FileAttrs := FileAttrs + faAnyFile;

  if FindFirst(Edit1.Text, FileAttrs, sr) = 0 then

  begin
    with StringGrid1 do
    begin
      if (sr.Attr and FileAttrs) = sr.Attr then
      begin
        Cells[1,RowCount-1] := sr.Name;
        Cells[2,RowCount-1] := IntToStr(sr.Size);
      end;
      while FindNext(sr) = 0 do
      begin
        if (sr.Attr and FileAttrs) = sr.Attr then
        begin
        RowCount := RowCount + 1;
        Cells[1, RowCount-1] := sr.Name;

        Cells[2, RowCount-1] := IntToStr(sr.Size);
        end;
      end;
      FindClose(sr);
    end;
  end;
end;

Porque ta lotado de check box e eu não sei ao certo oque eles estão qurendo fazer... Porq eu fiz da forma do seu 3º exemplo... funcionou perfeitamente.. Porém me lançaram uma pergunta "E se eu já estiver fazendo o filtro dessa tabela o que eu faço?" e minha rotina não iria servir pra isso.. se você puder tentar me explicar essa rotina pra mim tentar ver se consigo adapta-la pro componentes ADO eu agradeceria muito. Vlw Jhonas vlws mesmo, mas se puder me ajudar de novo...

Link para o comentário
Compartilhar em outros sites

  • 0

esse código serve para voce localizar um arquivo pelos seus atributos

como: se esta escondido, se esta somente como leitura, pelo tamanho, pelo diretorio ... etc

FileAttrs := FileAttrs + faSysFile;

a cada CheckBox ticado, mais um atributo de arquivo é adicionado para fazer a pesquisa, restringindo o escopo da pesquisa.

abraço

Link para o comentário
Compartilhar em outros sites

Participe da discussão

Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.

Visitante
Responder esta pergunta...

×   Você colou conteúdo com formatação.   Remover formatação

  Apenas 75 emoticons são permitidos.

×   Seu link foi incorporado automaticamente.   Exibir como um link em vez disso

×   Seu conteúdo anterior foi restaurado.   Limpar Editor

×   Você não pode colar imagens diretamente. Carregar ou inserir imagens do URL.



  • Estatísticas dos Fóruns

    • Tópicos
      152,1k
    • Posts
      651,7k
×
×
  • Criar Novo...