Rotina para configurar a propriedade tag

20/05/2009

Ola Pessoal   criei uma rotina para nao ter ficar escrevendo codigo em todos os formularios do projeto mais nao ta funcionando   essa rotina simplesmete verifica o tag       type
 tservicos =class(tform)
 class procedure TServicos.tag(xform: TForm);
end ;   -- na implementacao da classe class procedure TServicos.tag(xform: TForm);
var
  I, Y: integer;
  S: string; begin
  for y := 0 to ComponentCount - 1 do
  begin
    if (Components[y] is TComboBox) then
      if Components[y].Tag = 1 then
        if TComboBox(Components[y]).Text = EmptyStr then
        begin
          S := S + TComboBox(Components[y]).ImeName + #13;
        end;   end;
  for I := 0 to ComponentCount - 1 do
  begin
    if (Components[i] is TEdit) then
      if Components[i].Tag = 1 then
        if TEdit(Components[i]).Text = EmptyStr then
        begin
          S := S + TEdit(Components[i]).ImeName + #13;         end;
  end;   if S <> EmptyStr then
  begin
    raise
      Exception.Create('Informe:'
      +
      #13 + S);
  end;     tambem usei o refectore para adicionar as units da tcombobox e tedits mais nao sei pq nao funcionou  
Carlos Faria

Carlos Faria

Curtidas 0

Respostas

Carlos Faria

Carlos Faria

20/05/2009

vamos la esqueci de comentar eu acho que esta tudo certo porem da o seguinte erro     propriedade componentcount inacessivel daqui ?
GOSTEI 0
Rodrigo Mourão

Rodrigo Mourão

20/05/2009

Segue a rotina correta. Voce esqueceu de colcar o parametro do form antes do componentcount. Esta em vermelho.

class procedure TServicos.tag(xform: TForm);
var
  I, Y: integer;
  S: string; begin
  for y := 0 to xform.ComponentCount - 1 do
  begin
    if (xform.Components[y] is TComboBox) then
      if xform.Components[y].Tag = 1 then
        if TComboBox(xform.Components[y]).Text = EmptyStr then
        begin
          S := S + TComboBox(xform.Components[y]).ImeName + #13;
        end;   end;
  for I := 0 to xform.ComponentCount - 1 do
  begin
    if (xform.Components[i] is TEdit) then
      if xform.Components[i].Tag = 1 then
        if TEdit(xform.Components[i]).Text = EmptyStr then
        begin
          S := S + TEdit(xform.Components[i]).ImeName + #13;         end;
  end;   if S <> EmptyStr then
  begin
    raise
      Exception.Create('Informe:'
      +
      #13 + S);
  end;     tambem usei o refectore para adicionar as units da tcombobox e tedits mais nao sei pq nao funcionou  
GOSTEI 0
Carlos Faria

Carlos Faria

20/05/2009

ola deu tudo certo la do botao incluir do formulario tal como que eu faço para chamar a rotina antes do insert    
GOSTEI 0
Rodrigo Mourão

Rodrigo Mourão

20/05/2009

No seu formulario vc deve ter algum botão de Inserir ou entao Salvar. No evento onclick dele coloque o seguinte evento:

Tservico.Tag(self);

Simples assim !!!

Abs !!!
GOSTEI 0
Carlos Faria

Carlos Faria

20/05/2009

certo aqui vc pode dar um ok no chamado
GOSTEI 0
POSTAR