Sonda Web                                Directório - a sua melhor selecção de sites
Minha foto
Analista Programador Sênior. Delphiano desde 1998. Programador Delphi, PHP e Java

quarta-feira, 17 de fevereiro de 2010

Função Para Configurações de Botões

Hoje vou colocar uma função para vcs usarem em seus formulários de acesso a dados.
Para usa-la vc precisa só padronizar o nome dos botões.
{::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

Use quando tabela estiver em dsBrowse
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::;}
procedure BrowseState ( Form : TForm );
var i : Integer;
begin
  for i := 0 to Form.ComponentCount - 1 do
    begin
       if Form.Components[i] is TDBComboBox then
        begin
          ( Form.Components[i] as TDBComboBox).Style    := csSimple;
          ( Form.Components[i] as TDBComboBox).readOnly := True;
        end;

       if Form.Components[i] is TDBLookupComboBox then
         ( Form.Components[i] as TDBLookupComboBox).Enabled  := False;

       if Form.Components[i] is TDBEdit then
         ( Form.Components[i] as TDBEdit).ReadOnly := True;

       if Form.Components[i] is TDBCheckBox then
        begin
           ( Form.Components[i] as TDBCheckBox).ReadOnly := True;
           if ( Form.Components[i] as TDBCheckBox).State =  cbGrayed  then
             (Form.Components[i] as TDBCheckBox).State :=  cbUnchecked;
       end;

     if Form.Components[i] is TDBGrid then
         ( Form.Components[i] as TDBGrid).Enabled := True;

      if Form.Components[i] is TBitBtn then
       begin
         if( Form.Components[i] as TBitBtn).Name = 'BitBtnGravar' Then
           (Form.Components[i] as TBitBtn).Enabled := False;

         if( Form.Components[i] as TBitBtn).Name = 'BitBtnCancelar' Then
           (Form.Components[i] as TBitBtn).Enabled := False;

         if( Form.Components[i] as TBitBtn).Name = 'BitBtnIncluir' Then
           (Form.Components[i] as TBitBtn).Enabled := True;

         if( Form.Components[i] as TBitBtn).Name = 'BitBtnAlterar' Then
           (Form.Components[i] as TBitBtn).Enabled := True;

         if( Form.Components[i] as TBitBtn).Name = 'BitBtnExcluir' Then
           (Form.Components[i] as TBitBtn).Enabled := True;

         if( Form.Components[i] as TBitBtn).Name = 'BitBtnPesquisa' Then
           (Form.Components[i] as TBitBtn).Enabled := True;
       end;

      if Form.Components[i] is TDBNavigator then
         ( Form.Components[i] as TDBNavigator).Enabled := True;
    end;
end;

{:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 
 Fim Função BowseState
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::;}




{:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 
Use quando tabela estiver em dsInsert ou DsEdit
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::;}
Procedure InsertState ( Form : TForm );

var i : Integer;
begin
   for i := 0 to Form.ComponentCount - 1 do
     begin
        if Form.Components[i] is TDBComboBox then
         begin
           ( Form.Components[i] as TDBComboBox).Style    := csDropDown;
           ( Form.Components[i] as TDBComboBox).readOnly := False;
           ( Form.Components[i] as TDBComboBox).Enabled  := True;
        end;

        if Form.Components[i] is TDBLookupComboBox then
           ( Form.Components[i] as TDBLookupComboBox).Enabled  := True;

      if Form.Components[i] is TDBEdit then
         ( Form.Components[i] as TDBEdit).ReadOnly := False;

      if Form.Components[i] is TDBCheckBox then
        begin
          ( Form.Components[i] as TDBCheckBox).ReadOnly := False;
          (Form.Components[i] as TDBCheckBox).State     :=  cbUnchecked;
        end;
      if Form.Components[i] is TBitBtn then
       Begin
         if( Form.Components[i] as TBitBtn).Name = 'BitBtnIncluir' Then
           (Form.Components[i] as TBitBtn).Enabled := False;

         if( Form.Components[i] as TBitBtn).Name = 'BitBtnAlterar' Then
           (Form.Components[i] as TBitBtn).Enabled := False;

         if( Form.Components[i] as TBitBtn).Name = 'BitBtnExcluir' Then
           (Form.Components[i] as TBitBtn).Enabled := False;

         if( Form.Components[i] as TBitBtn).Name = 'BitBtnCancelar' Then
           (Form.Components[i] as TBitBtn).Enabled := True;

         if( Form.Components[i] as TBitBtn).Name = 'BitBtnGravar' Then
           (Form.Components[i] as TBitBtn).Enabled := True;

         if( Form.Components[i] as TBitBtn).Name = 'BitBtnPesquisa' Then
           (Form.Components[i] as TBitBtn).Enabled := False;
       end;

      if Form.Components[i] is TDBGrid then
         ( Form.Components[i] as TDBGrid).Enabled := False;

      if Form.Components[i] is TDBNavigator then
         ( Form.Components[i] as TDBNavigator).Enabled := False;
    end;
end;
{:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 
 Fim Função InsertState
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::;}
para chama-la é muito simples :
em seu form de cadastro  de clientes no botão Incluir
Procedure TF_Cllientes.BitbtnIncluir.click(Sender : Tobject);
begin
    Sua_Tabela_Clientes.Insert;
    InsertState( F_Clientes );
end. 

Qualquer dúvida só escreverem.

Nenhum comentário:

Postar um comentário