Fórum listview #396878

07/03/2011

0

oi to com uma duvidazinha to usando esse codigo para ñ se reepetir a maatricula
so q msm assim ela sta salvando iguais
ond sta errado?

var
  existeMatricula: Boolean;
begin
  existeMatricula := False;
  for i := 0 to ListView1.Items.Count - 1 do
  begin
    if  ListView1.Items.Item[i].Caption = txtMatricula.text then
      begin
        existeMatricula := True;

        Break;
      end
  
  end;
 

????????

Alessandra

Alessandra

Responder

Posts

07/03/2011

Marco Salles

var
  existeMatricula: Boolean;
begin
  existeMatricula := False;
  for i := 0 to ListView1.Items.Count - 1 do
  begin
    if  ListView1.Items.Item[i].Caption = txtMatricula.text then
      begin
        existeMatricula := True;

        Break;
      end
   
  end;
  A ideia esta certa ,,, Mas como vc esta  utilizando este método ???   Veja  
function TForm1.VefificarItem(List:TListView;caption:String): boolean;
var
i:Integer;
begin
result:=(False);
 for i := 0 to List.Items.Count-1  do
   if List.Items.Item[i].Caption = caption then
      begin
        result:=True;
        Break
      end;
end;
  Da mesma forma que o tópico anteirior  
procedure TForm1.Button1Click(Sender: TObject);
begin
 if VerificarVazio(Edit1.Text,Edit2.Text,Edit3.Text) then
   if not VefificarItem(ListView1,edit1.Text) then
     PreenCherListView;
end;
  Ver a continuação desse post em : https://www.devmedia.com.br/forum/delphi/396806-delphi7.html

Responder

Gostei + 0

08/03/2011

Alessandra

estouusando assim pra chamar a função 

begin
  if  ExisteMatricula(txtMatricula.Text) then
      ShowMessage('Matrícula já existe!')
  else
      //Sua rotina para salvar a matrícula
  ;
end;

so q sta dando erro ao chamar

Responder

Gostei + 0

08/03/2011

Alessandra

estouusando assim pra chamar a função 

begin
  if  ExisteMatricula(txtMatricula.Text) then
      ShowMessage('Matrícula já existe!')
  else

end;

so q sta dando erro ao chamar

Responder

Gostei + 0

08/03/2011

Marco Salles

estouusando assim pra chamar a função 

begin
  if  ExisteMatricula(txtMatricula.Text) then
      ShowMessage('Matrícula já existe!')
  else
      //Sua rotina para salvar a matrícula
  ;
end;

so q sta dando erro ao chamar

  do jeito que lhe postei antes funciona. Mas não é o único modo . Como vc esta definidno e implementando a Function ExisteMatricula ??? Quais os parâmetros que vc definiu para ela ???  
Responder

Gostei + 0

08/03/2011

Alessandra

stou usando a função asssim

function ExisteMatricula(Matricula: string): Boolean;
var
  x: integer;
begin
  Result := False;

  for x := 0 to ListView_Funcionario.Items.Count - 1 do
  begin
    if  ListView_Funcionario.Items.Item[x].Caption = Matricula then
      begin
        Result := True;
        Break;
      end

 
end;



e pra chamar a função assim

begin
  if  ExisteMatricula(txtMatricula.Text) then
      ShowMessage('Matrícula já existe!')
  else
      //Sua rotina para salvar a matrícula
  ;
end;

Responder

Gostei + 0

08/03/2011

Marco Salles

Olha Alessandra . Erro de lógica não é . O único erro que vejo nesta tua rotina é erro de sintaxi como a função do jeito que vc definiu não é uma função de instância ela não consegue enxergar ListView_Funcionario que pertence ao formulario em questão Ou vc define esta função na parte private do form , ou antes do ListView_Funcionario  , vc coloca a instancia do formulario que é proprietário do ListView_Funcionario  
function ExisteMatricula(Matricula: string): Boolean;
var
  x: integer;
begin
  Result := False;

  for x := 0 to SeuForm.ListView_Funcionario.Items.Count - 1 do
  begin
    if  SeuForm.ListView_Funcionario.Items.Item[x].Caption = Matricula then
      begin
        Result := True;
        Break;
      end
end;
ps)quero acrescentar que tanto a funçao na parte private , tanto definir o proprietário no proprio método são souluçoes paleativas e sem nenhum requinte de OO , o que não deve ser feito em larga escala e nen ser colocado em produção
Responder

Gostei + 0

09/03/2011

Alessandra

eu fiz cm vc falou sobre colocar antes do listview funcionario e tbm cm o prof tinha falado para colocar no final doprojeto ai deu um erro que não tinha identificado  -> if  ExisteMatricula(txtMatricula.Text) then sobre coloca-la
no private do form ainda ñ sei cm se faz, ainda ñ xegamos nessa part na aula, fiz uma pesquisa no google + as rspostas ñ foram claras, se puder me falar cm fazer eu agradasço muito
                                                                                

Responder

Gostei + 0

09/03/2011

Marco Salles

eu fiz cm vc falou sobre colocar antes do listview funcionario e tbm cm o prof tinha falado para colocar no final doprojeto ai deu um erro que não tinha identificado  -> if  ExisteMatricula(txtMatricula.Text) then sobre coloca-la
no private do form ainda ñ sei cm se faz, ainda ñ xegamos nessa part na aula, fiz uma pesquisa no google + as rspostas ñ foram claras, se puder me falar cm fazer eu agradasço muito
. Eu não disse para colocar somente antes , eu disse que alem de ser antes a definição do método tem que alem disso colocar o Nome Do formulário que é proprietário do ListWiew Perceba   function ExisteMatricula(Matricula: string): Boolean;
var
  x: integer;
begin
  Result := False;

  for x := 0 to SeuForm.ListView_Funcionario.Items.Count - 1 do
  begin
    if  SeuForm.ListView_Funcionario.Items.Item[x].Caption = Matricula then
      begin
        Result := True;
        Break;
      end
end; ,   SeuForm >>>> É o Nome do Form  .. Form1  por exemplo   Colocar no Private do Form é somente a DECÇARAÇÃO   Por exemplo   type
  TForm1 = class(TForm)
     private       function ExisteMatricula(Matricula: string): Boolean;  //AQUI A DECLARAÇÃO
    { Private declarations }
  public
    { Public declarations }
  end;   Apos isto colocque o Cursor Sobre a Declaração e de simultaneamente Um CNTR+SHIFT+C   o DELPHI abrira para vc a parte da IMPLEMENTAÇÃO  
function TForm1.ExisteMatricula(Matricula: string): Boolean;
var
  x: integer;
begin
  Result := False;

  for x := 0 to ListView_Funcionario.Items.Count - 1 do
  begin
    if  ListView_Funcionario.Items.Item[x].Caption = Matricula then
      begin
        Result := True;
        Break;
      end

end;
  Neste Ultimo caso , não precisa colocar o Nome do Form , pois o método é do Próprio Form   Espero que vc faça com calma e leia com atenção   Boa sorte

Responder

Gostei + 0

09/03/2011

Alessandra

agradeço muito funciono sim
muito obrigada
Responder

Gostei + 0

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

Aceitar