Fórum Verificar campos iguais #376763
01/05/2010
0
begin
for a := 1 to 10 do
begin
for b := 1 to 10 do
begin
if (TEdit(Formulario.Components[a]).Text) = (TEdit(Formulario.Components[b]).Text) then
begin
label1.caption := 'Há campos iguais em ' + a + ' e ' + b;
end;
end;
end;
end;
Carlos
Curtir tópico
+ 0Posts
01/05/2010
Emerson Nascimento
var
a, b: integer;
compa, compb: TComponent;
iguais: TStringList;
s: string;
begin
iguais := TStringList.Create;
iguais.Sorted := True;
s := '';
for a := 0 to Formulario.ComponentCount-1 do
begin
compa := Formulario.Components[a];
for b := 0 to Formulario.ComponentCount-1 do
begin
compb := Formulario.Components[b];
if (compa is TEdit) and (compb is TEdit) and (compa <> compb)
and (TEdit(compa).Text = TEdit(compb).Text)
and ((iguais.IndexOf(compa.Name) < 0) or (iguais.IndexOf(compb.Name) < 0)) then
begin
if s <> '' then s := s + '; ';
s := s + compa.Name + ' e ' + compb.Name;
iguais.Add(compa.Name);
iguais.Add(compb.Name);
end;
end;
end;
if s <> '' then
label1.caption := 'Há valores iguais em ' + s
else
label1.caption := 'Não há valores iguais.';
end
Gostei + 0
03/05/2010
Wilson Junior
var x, y: integer; ValorIgual: string; begin ValorIgual := ''; for x := 0 to Formulario.ComponentCount do begin if ValorIgual <> '' then Break ; if Formulario.Components[x] is TEdit then begin for y := x + 1 to Formulario.ComponentCount - 1 do begin if Formulario.Components[y] is TEdit then begin if TEdit(Formulario.Components[x]).Text = TEdit(Formulario.Components[y]).Text then begin ValorIgual := TEdit(Formulario.Components[x]).Text; Break; end ; end ; end; end ; end; if ValorIgual = '' then label1.caption := 'Não há valores iguais' else label1.caption := 'Há valores iguais em ' + ValorIgual ; end;
Espero ter colaborado.
Gostei + 0
06/05/2010
Carlos
Oque estou tetanto e verificar se tem campos iguais nos campos contidos em painel com o nome de formulario.
Obrigado pela ajuda, aguardo retorno.
Gostei + 0
06/05/2010
Wilson Junior
Em que momento ocorre este erro?
Aguardo retorno.
Gostei + 0
06/05/2010
Wilson Junior
for x := 0 to Formulario.ComponentCount - 1 do
Espero ter colaborado.
Gostei + 0
06/05/2010
Carlos
http://img708.imageshack.us/img708/6923/janela.jpg
Obrigado aguardo retorno.
Gostei + 0
06/05/2010
Wilson Junior
Aguardo retorno.
Gostei + 0
06/05/2010
Carlos
http://uploaddearquivos.com.br/download/Verifica-campos.rar
Aguardo retorno.
Gostei + 0
06/05/2010
Emerson Nascimento
procedure Tfrm_verificar.Button1Click(Sender: TObject);
var
a, b: integer;
compa, compb: TComponent;
iguais: TStringList;
s: string;
begin
iguais := TStringList.Create;
iguais.Sorted := True;
s := '';
for a := 0 to ComponentCount-1 do
begin
compa := Components[a];
for b := 0 to ComponentCount-1 do
begin
compb := Components[b];
if (compa is TEdit) and (compb is TEdit) and (compa <> compb)
and (TEdit(compa).Text = TEdit(compb).Text)
and ((iguais.IndexOf(compa.Name) < 0) or (iguais.IndexOf(compb.Name) < 0)) then
begin
if s <> '' then s := s + '; ';
s := s + compa.Name + ' e ' + compb.Name;
iguais.Add(compa.Name);
iguais.Add(compb.Name);
end;
end;
end;
if s <> '' then
MessageBox(0, PChar('Há valores iguais em ' + s), 'Campos iguais!', 0)
else
MessageBox(0, 'Não há valores iguais.', 'Campos iguais!', 0);
end;
você precisa tirar a referência à Formulario.
Formulario é um painel; apesar dos edits estarem dentro do painel, eles pertencem ao formulário Tfrm_verificar, portanto se quiser referenciar algo, referencie o próprio formulário.
Gostei + 0
06/05/2010
Carlos
Gostei + 0
06/05/2010
Carlos
Gostei + 0
06/05/2010
Marco Salles
Gostei + 0
06/05/2010
Carlos
Gostei + 0
07/05/2010
Marco Salles
var
a, b: integer;
compa, compb: TComponent;
iguais: TStringList;
s: string;
begin
iguais := TStringList.Create;
iguais.Sorted := True;
s := ''; for a := 0 to Controle.ControlCount -1 do
begin
if (controle.Controls[a] is TEdit)and(controle.Controls[a].Tag=1) then
compa := controle.Controls[a];
for b := 0 to controle.ControlCount-1 do
begin
if (controle.Controls[b] is TEdit)and(controle.Controls[b].Tag=1) then
begin
compb := controle.Controls[b];
if (compa <> compb)
and (TEdit(compa).Text = TEdit(compb).Text)
and ((iguais.IndexOf(compa.Name) < 0) or (iguais.IndexOf(compb.Name) < 0)) then
begin
if s <> '' then s := s + '; ';
s := s + compa.Name + ' e ' + compb.Name;
iguais.Add(compa.Name);
iguais.Add(compb.Name);
end;
end;
end;
end; if s <> '' then
MessageBox(0, PChar('Há valores iguais em ' + s), 'Campos iguais!', 0)
else
MessageBox(0, 'Não há valores iguais.', 'Campos iguais!', 0);
end;
para chamar faça procedure TForm1.Button1Click(Sender: TObject);
begin
Verifica(panel1); // Seu panel ,,, no caso o seu container
end; ps) eu prefiro mil vezes a classe mas vc tem direito a um so pedido ..rsssssss
Gostei + 0
07/05/2010
Marco Salles
class procedure Comparar(Colecao:Array of TEdit);
end;
class procedure TVerificarEdit.Comparar(Colecao: array of TEdit);
var
i,j:integer;
iguais: TStringList;
edta,edtb:TEdit;
s: string;
begin
iguais := TStringList.Create;
try
iguais.Sorted := True;
s := '';
for i := 0 to High(Colecao) do
begin
edta := Colecao[i];
for j := 0 to High(Colecao) do
begin
edtb:=Colecao[j];
if (edtA <> Edtb)
and (EdtA.Text = EdtB.Text)
and ((iguais.IndexOf(EdtA.Name) < 0) or (iguais.IndexOf(EdtB.Name) < 0)) then
begin
if s <> '' then s := s + '; ';
s := s + EdtA.Name + ' e ' + EdtB.Name;
iguais.Add(EdtA.Name);
iguais.Add(EdtB.Name);
end;
end;
end;
if s <> '' then
MessageBox(0, PChar('Há valores iguais em ' + s), 'Campos iguais!', 0)
else
MessageBox(0, 'Não há valores iguais.', 'Campos iguais!', 0);
finally
iguais.Free;
end; para chamar procedure TForm1.Button1Click(Sender: TObject);
begin
TVerificarEdit.Comparar([edit3,edit4,edit6,edit7]); // onde esses edits são os que eu quero que sofra comparações
end; TVerificarEdit = class
class procedure Comparar(Colecao:Array of TEdit);
end;
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)