listview
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;
????????
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
Curtidas 0
Respostas
Marco Salles
07/03/2011
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;
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;
procedure TForm1.Button1Click(Sender: TObject); begin if VerificarVazio(Edit1.Text,Edit2.Text,Edit3.Text) then if not VefificarItem(ListView1,edit1.Text) then PreenCherListView; end;
GOSTEI 0
Alessandra
07/03/2011
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
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
GOSTEI 0
Alessandra
07/03/2011
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
begin
if ExisteMatricula(txtMatricula.Text) then
ShowMessage('Matrícula já existe!')
else
end;
so q sta dando erro ao chamar
GOSTEI 0
Marco Salles
07/03/2011
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 ???
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
GOSTEI 0
Alessandra
07/03/2011
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;
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;
GOSTEI 0
Marco Salles
07/03/2011
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
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
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;
GOSTEI 0
Alessandra
07/03/2011
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
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
GOSTEI 0
Marco Salles
07/03/2011
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;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
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;
GOSTEI 0
Alessandra
07/03/2011
agradeço muito funciono sim
muito obrigada
muito obrigada
GOSTEI 0