Controle de Botões Page Control Delphi 2010

20/02/2013

1

Olá Pessoal Estou com um pequeno problema com Page Control eu tenho um Controle de botões de ativabtn e Desativabtn e tenho tambem ativa e desativa dbedits, quando eu clico no botão novo ele ativa os botões e os dbedits para edição, mais aqui no pagecontrol só ativa dos dbedits e botoes do tabesheet1 do tabsheet2 nao ativa alguem sabe porque...
Responder

Posts

Olá Pessoal Estou com um pequeno problema com Page Control eu tenho um Controle de botões de ativabtn e Desativabtn e tenho tambem ativa e desativa dbedits, quando eu clico no botão novo ele ativa os botões e os dbedits para edição, mais aqui no pagecontrol só ativa dos dbedits e botoes do tabesheet1 do tabsheet2 nao ativa alguem sabe porque...


Mostre como vocês está fazendo esse controle, assim fica melhor para que possamos lhe ajudar.


Boa sorte e bons códigos.
Responder
Colega, tente fazer como no exemplo abaixo:
procedure TXXXXXX.ds1StateChange(Sender: TObject); //Evento OnStateChange do DataSource
var
  i: integer; //Variável inteira para ser usada na instrução for do
begin
  //Ativando / Desativando Botões
  Button2.Enabled := ds1.State in [dsBrowse]; //Novo
  Button3.Enabled := ds1.State in [dsBrowse]; //Editar
  Button4.Enabled := ds1.State in [dsBrowse]; //Excluir
  Button5.Enabled := ds1.State in [dsInsert,dsEdit]; //Gravar
  Button6.Enabled := ds1.State in [dsInsert, dsEdit]; //Cancelar

  //Ativando / Desativando DBEdits e Edits, podemos usar para outros componentes
  for I := 0 to ComponentCount -1 do
    begin
      if (Components[i] is TCustomEdit) then
      (Components[i] as TCustomEdit).Enabled := ds1.State in [dsInsert, dsEdit];
    end;
end;


Teste o exemplo acima, se apresentar algum erro retorne aqui, foi escrito fora do Delphi, por isso não testei antes.

Boa sorte e bons códigos!
Responder
Bom vou tentar me explicar melhor, segue abaixo meu codigo.

Obs:Banco Firebird, Delphi 2010.

#Código

unit U_CadVeiculos1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons, ExtCtrls, ComCtrls, DB, Mask, DBCtrls, FMTBcd,
SqlExpr, ExtDlgs;

type
TF_CadVeiculo1 = class(TForm)
PageControl1: TPageControl;
TabSheet1: TTabSheet;
TabSheet2: TTabSheet;
Panel1: TPanel;
Panel2: TPanel;
Panel3: TPanel;
btn_editar: TBitBtn;
btn_cancelar: TBitBtn;
btn_excluir: TBitBtn;
btn_gravar: TBitBtn;
btn_pesquisar: TBitBtn;
btn_sair: TBitBtn;
btn_novo: TBitBtn;
Label1: TLabel;
DBEdit1: TDBEdit;
Label4: TLabel;
DBEdit4: TDBEdit;
Label2: TLabel;
DBEdit2: TDBEdit;
DBEdit3: TDBEdit;
Label5: TLabel;
DBEdit5: TDBEdit;
Label6: TLabel;
DBEdit7: TDBEdit;
Label3: TLabel;
DBEdit6: TDBEdit;
Label7: TLabel;
DBEdit8: TDBEdit;
Label8: TLabel;
DBEdit9: TDBEdit;
Label9: TLabel;
DBEdit10: TDBEdit;
Label11: TLabel;
DBEdit12: TDBEdit;
DBEdit13: TDBEdit;
Label12: TLabel;
DBEdit11: TDBEdit;
Label10: TLabel;
Label15: TLabel;
DBEdit16: TDBEdit;
Label13: TLabel;
DBEdit14: TDBEdit;
Label14: TLabel;
DBEdit15: TDBEdit;
DBEdit17: TDBEdit;
Label16: TLabel;
Foto1: TImage;
Bevel1: TBevel;
Label17: TLabel;
DBEdit18: TDBEdit;
btn_foto1: TBitBtn;
Image2: TImage;
Bevel2: TBevel;
Label18: TLabel;
DBEdit19: TDBEdit;
btn_foto2: TBitBtn;
Image3: TImage;
Bevel3: TBevel;
Label19: TLabel;
DBEdit20: TDBEdit;
btn_foto3: TBitBtn;
Image4: TImage;
Bevel4: TBevel;
Label20: TLabel;
DBEdit21: TDBEdit;
btn_foto4: TBitBtn;
TabSheet3: TTabSheet;
Panel4: TPanel;
Image5: TImage;
Bevel5: TBevel;
Label21: TLabel;
Image6: TImage;
Bevel6: TBevel;
Label22: TLabel;
Image7: TImage;
Bevel7: TBevel;
Label23: TLabel;
Image8: TImage;
Bevel8: TBevel;
Label24: TLabel;
DBEdit22: TDBEdit;
btn_foto5: TBitBtn;
DBEdit23: TDBEdit;
btn_foto6: TBitBtn;
DBEdit24: TDBEdit;
btn_foto7: TBitBtn;
DBEdit25: TDBEdit;
btn_foto8: TBitBtn;
DataSource1: TDataSource;
SP_GEN_VEICULOS: TSQLStoredProc;
abrindo_foto1: TOpenPictureDialog;
procedure btn_sairClick(Sender: TObject);
procedure Desativabtn;
procedure ativabtn;
Procedure ativadbedit;
Procedure desativadbedit;
procedure btn_novoClick(Sender: TObject);
procedure btn_foto1Click(Sender: TObject);
procedure DBEdit18Change(Sender: TObject);
procedure btn_gravarClick(Sender: TObject);
procedure btn_editarClick(Sender: TObject);
procedure btn_cancelarClick(Sender: TObject);
procedure btn_excluirClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
F_CadVeiculo1: TF_CadVeiculo1;

implementation

uses U_Principal, U_DM;

{$R *.dfm}

Procedure TF_CadVeiculo1.ativadbedit;

begin
DBEdit2.enabled := True;
DBEdit3.enabled := True;
DBEdit4.enabled := True;
DBEdit5.enabled := True;
DBEdit6.enabled := True;
DBEdit7.enabled := True;
DBEdit8.enabled := True;
DBEdit9.enabled := True;
DBEdit10.enabled := True;
DBEdit11.enabled := True;
DBEdit12.enabled := True;
DBEdit13.enabled := True;
DBEdit14.enabled := True;
DBEdit15.enabled := True;
DBEdit16.enabled := True;
DBEdit17.enabled := True;
DBEdit18.enabled := True;
DBEdit19.enabled := True;
DBEdit20.enabled := True;
DBEdit21.enabled := True;
DBEdit22.enabled := True;
DBEdit23.enabled := True;
DBEdit24.enabled := True;
DBEdit25.enabled := True;
end;

procedure TF_CadVeiculo1.ativabtn;
begin
btn_novo.enabled := True;
btn_editar.enabled := True;
btn_cancelar.enabled := False;
btn_gravar.enabled := False;
btn_excluir.enabled := True;
btn_sair.enabled := True;
btn_pesquisar.enabled := True;
btn_foto1.enabled := True;
btn_foto2.enabled := True;
btn_foto3.enabled := True;
btn_foto4.enabled := True;
btn_foto5.enabled := True;
btn_foto6.enabled := True;
btn_foto7.enabled := True;
btn_foto8.enabled := True;

end;

procedure TF_CadVeiculo1.DBEdit18Change(Sender: TObject);
begin
if not FileExists(DBEdit18.Text) then
Foto1.Picture := nil

Else

Foto1.Picture.LoadFromFile(DBEdit18.Text);
end;

procedure TF_CadVeiculo1.Desativabtn;
begin
btn_novo.enabled := False;
btn_editar.enabled := False;
btn_cancelar.enabled := True;
btn_gravar.enabled := True;
btn_excluir.enabled := False;
btn_sair.enabled := False;
btn_pesquisar.enabled := False;
btn_foto1.enabled := False;
btn_foto2.enabled := False;
btn_foto3.enabled := False;
btn_foto4.enabled := False;
btn_foto5.enabled := False;
btn_foto6.enabled := False;
btn_foto7.enabled := False;
btn_foto8.enabled := False;
end;

procedure TF_CadVeiculo1.desativadbedit;
begin
DBEdit2.enabled := False;
DBEdit3.enabled := False;
DBEdit4.enabled := False;
DBEdit5.enabled := False;
DBEdit6.enabled := False;
DBEdit7.enabled := False;
DBEdit8.enabled := False;
DBEdit9.enabled := False;
DBEdit10.enabled := False;
DBEdit11.enabled := False;
DBEdit12.enabled := False;
DBEdit13.enabled := False;
DBEdit14.enabled := False;
DBEdit15.enabled := False;
DBEdit16.enabled := False;
DBEdit17.enabled := False;
DBEdit18.enabled := False;
DBEdit19.enabled := False;
DBEdit20.enabled := False;
DBEdit21.enabled := False;
DBEdit22.enabled := False;
DBEdit23.enabled := False;
DBEdit24.enabled := False;
DBEdit25.enabled := False;
end;

procedure TF_CadVeiculo1.btn_cancelarClick(Sender: TObject);
begin //Botão Cancelar//
if DataSource1.DataSet.State in [dsBrowse, dsEdit, dsInsert] then

begin
DM.CDS_CLIENTE.Cancel;
DM.CDS_CLIENTE.ApplyUpdates(0);
DM.CDS_CLIENTE.Open;
DM.CDS_CLIENTE.close;
ativabtn;
end;
end;

procedure TF_CadVeiculo1.btn_editarClick(Sender: TObject);
begin
DM.CDS_CLIENTE.Edit;
Desativabtn;
ativadbedit;
end;

procedure TF_CadVeiculo1.btn_excluirClick(Sender: TObject);
begin //Botão Excluir//
if DataSource1.DataSet.State in [dsBrowse, dsEdit] then
begin
DM.CDS_CLIENTE.Delete;
DM.CDS_CLIENTE.ApplyUpdates(0);
DM.CDS_CLIENTE.close;
end;
end;

procedure TF_CadVeiculo1.btn_foto1Click(Sender: TObject);
begin //abrindo a foto1//
if abrindo_foto1.Execute then
Foto1.Picture.LoadFromFile(abrindo_foto1.FileName);
DBEdit18.Text:=abrindo_foto1.FileName;
end;

procedure TF_CadVeiculo1.btn_gravarClick(Sender: TObject);
begin //Botão Gravar//
if DM.CDS_CLIENTE.State in [dsBrowse, dsEdit, dsInsert] then

begin
DM.CDS_CLIENTE.Post;
DM.CDS_CLIENTE.ApplyUpdates(0);
DM.CDS_CLIENTE.close;
ATIVABTN;
end;
end;

procedure TF_CadVeiculo1.btn_novoClick(Sender: TObject);
var
vID: integer;
begin
with SP_GEN_VEICULOS do
begin
Prepared := True;
ExecProc;
Prepared := False;
vID := ParamByName('ID').Value;
close;
end;
DM.CDS_VEICULO.Open;
DM.CDS_VEICULO.Append;
DM.CDS_VEICULO.FieldByName('ID').AsInteger := vID;
Desativabtn;
ativadbedit;
btn_gravar.SetFocus;
end;


procedure TF_CadVeiculo1.btn_sairClick(Sender: TObject);
begin
Close;
end;

end.
Responder
pessoal consegui resolver meu problema... segue anexo o

#Código

unit U_CadVeiculos1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons, ExtCtrls, ComCtrls, DB, Mask, DBCtrls, FMTBcd,
SqlExpr, ExtDlgs;

type
TF_CadVeiculo1 = class(TForm)
PageControl1: TPageControl;
TabSheet1: TTabSheet;
TabSheet2: TTabSheet;
Panel1: TPanel;
Panel2: TPanel;
Panel3: TPanel;
btn_editar: TBitBtn;
btn_cancelar: TBitBtn;
btn_excluir: TBitBtn;
btn_gravar: TBitBtn;
btn_pesquisar: TBitBtn;
btn_sair: TBitBtn;
btn_novo: TBitBtn;
Label1: TLabel;
DBEdit1: TDBEdit;
Label4: TLabel;
DBEdit4: TDBEdit;
Label2: TLabel;
DBEdit2: TDBEdit;
DBEdit3: TDBEdit;
Label5: TLabel;
DBEdit5: TDBEdit;
Label6: TLabel;
DBEdit7: TDBEdit;
Label3: TLabel;
DBEdit6: TDBEdit;
Label7: TLabel;
DBEdit8: TDBEdit;
Label8: TLabel;
DBEdit9: TDBEdit;
Label9: TLabel;
DBEdit10: TDBEdit;
Label11: TLabel;
DBEdit12: TDBEdit;
DBEdit13: TDBEdit;
Label12: TLabel;
DBEdit11: TDBEdit;
Label10: TLabel;
Label15: TLabel;
DBEdit16: TDBEdit;
Label13: TLabel;
DBEdit14: TDBEdit;
Label14: TLabel;
DBEdit15: TDBEdit;
DBEdit17: TDBEdit;
Label16: TLabel;
Foto1: TImage;
Bevel1: TBevel;
Label17: TLabel;
DBEdit18: TDBEdit;
btn_foto1: TBitBtn;
Image2: TImage;
Bevel2: TBevel;
Label18: TLabel;
DBEdit19: TDBEdit;
btn_foto2: TBitBtn;
Image3: TImage;
Bevel3: TBevel;
Label19: TLabel;
DBEdit20: TDBEdit;
btn_foto3: TBitBtn;
Image4: TImage;
Bevel4: TBevel;
Label20: TLabel;
DBEdit21: TDBEdit;
btn_foto4: TBitBtn;
TabSheet3: TTabSheet;
Panel4: TPanel;
Image5: TImage;
Bevel5: TBevel;
Label21: TLabel;
Image6: TImage;
Bevel6: TBevel;
Label22: TLabel;
Image7: TImage;
Bevel7: TBevel;
Label23: TLabel;
Image8: TImage;
Bevel8: TBevel;
Label24: TLabel;
DBEdit22: TDBEdit;
btn_foto5: TBitBtn;
DBEdit23: TDBEdit;
btn_foto6: TBitBtn;
DBEdit24: TDBEdit;
btn_foto7: TBitBtn;
DBEdit25: TDBEdit;
btn_foto8: TBitBtn;
DataSource1: TDataSource;
SP_GEN_VEICULOS: TSQLStoredProc;
abrindo_foto1: TOpenPictureDialog;
procedure btn_sairClick(Sender: TObject);
procedure Desativabtn;
procedure ativabtn;
Procedure ativadbedit;
Procedure desativadbedit;
procedure btn_novoClick(Sender: TObject);
procedure btn_foto1Click(Sender: TObject);
procedure DBEdit18Change(Sender: TObject);
procedure btn_gravarClick(Sender: TObject);
procedure btn_editarClick(Sender: TObject);
procedure btn_cancelarClick(Sender: TObject);
procedure btn_excluirClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
F_CadVeiculo1: TF_CadVeiculo1;

implementation

uses U_Principal, U_DM;

{$R *.dfm}

Procedure TF_CadVeiculo1.ativadbedit;

begin
DBEdit2.enabled := True;
DBEdit3.enabled := True;
DBEdit4.enabled := True;
DBEdit5.enabled := True;
DBEdit6.enabled := True;
DBEdit7.enabled := True;
DBEdit8.enabled := True;
DBEdit9.enabled := True;
DBEdit10.enabled := True;
DBEdit11.enabled := True;
DBEdit12.enabled := True;
DBEdit13.enabled := True;
DBEdit14.enabled := True;
DBEdit15.enabled := True;
DBEdit16.enabled := True;
DBEdit17.enabled := True;
DBEdit18.enabled := True;
DBEdit19.enabled := True;
DBEdit20.enabled := True;
DBEdit21.enabled := True;
DBEdit22.enabled := True;
DBEdit23.enabled := True;
DBEdit24.enabled := True;
DBEdit25.enabled := True;
end;

procedure TF_CadVeiculo1.ativabtn;
begin
btn_novo.enabled := True;
btn_editar.enabled := True;
btn_cancelar.enabled := False;
btn_gravar.enabled := False;
btn_excluir.enabled := True;
btn_sair.enabled := True;
btn_pesquisar.enabled := True;


end;

procedure TF_CadVeiculo1.DBEdit18Change(Sender: TObject);
begin
if not FileExists(DBEdit18.Text) then
Foto1.Picture := nil

Else

Foto1.Picture.LoadFromFile(DBEdit18.Text);
end;

procedure TF_CadVeiculo1.Desativabtn;
begin
btn_novo.enabled := False;
btn_editar.enabled := False;
btn_cancelar.enabled := True;
btn_gravar.enabled := True;
btn_excluir.enabled := False;
btn_sair.enabled := False;
btn_pesquisar.enabled := False;

end;

procedure TF_CadVeiculo1.desativadbedit;
begin
DBEdit2.enabled := False;
DBEdit3.enabled := False;
DBEdit4.enabled := False;
DBEdit5.enabled := False;
DBEdit6.enabled := False;
DBEdit7.enabled := False;
DBEdit8.enabled := False;
DBEdit9.enabled := False;
DBEdit10.enabled := False;
DBEdit11.enabled := False;
DBEdit12.enabled := False;
DBEdit13.enabled := False;
DBEdit14.enabled := False;
DBEdit15.enabled := False;
DBEdit16.enabled := False;
DBEdit17.enabled := False;
DBEdit18.enabled := False;
DBEdit19.enabled := False;
DBEdit20.enabled := False;
DBEdit21.enabled := False;
DBEdit22.enabled := False;
DBEdit23.enabled := False;
DBEdit24.enabled := False;
DBEdit25.enabled := False;
end;

procedure TF_CadVeiculo1.btn_cancelarClick(Sender: TObject);
begin
if DataSource1.DataSet.State in [dsBrowse, dsEdit, dsInsert] then

begin
DM.CDS_VEICULO.Cancel;
DM.CDS_VEICULO.ApplyUpdates(-1);
DM.CDS_VEICULO.Open;
DM.CDS_VEICULO.close;
ativabtn;
btn_foto1.enabled := False;
btn_foto2.enabled := False;
btn_foto3.enabled := False;
btn_foto4.enabled := False;
btn_foto5.enabled := False;
btn_foto6.enabled := False;
btn_foto7.enabled := False;
btn_foto8.enabled := False;
end
else
ShowMessage('Atenção: Favor Executar uma Operação.');
end;

procedure TF_CadVeiculo1.btn_editarClick(Sender: TObject);
begin
DM.CDS_VEICULO.Edit;
Desativabtn;
ativadbedit;
end;

procedure TF_CadVeiculo1.btn_excluirClick(Sender: TObject);
begin //Botão Excluir//
if DataSource1.DataSet.State in [dsBrowse, dsEdit] then
begin
DM.CDS_VEICULO.Delete;
DM.CDS_VEICULO.ApplyUpdates(0);
DM.CDS_VEICULO.close;
end;
end;

procedure TF_CadVeiculo1.btn_foto1Click(Sender: TObject);
begin //abrindo a foto1//
if abrindo_foto1.Execute then
Foto1.Picture.LoadFromFile(abrindo_foto1.FileName);
DBEdit18.Text:=abrindo_foto1.FileName;
end;

procedure TF_CadVeiculo1.btn_gravarClick(Sender: TObject);
begin //Botão Gravar//
if DM.CDS_VEICULO.State in [dsBrowse, dsEdit, dsInsert] then

begin
DM.CDS_VEICULO.Post;
DM.CDS_VEICULO.ApplyUpdates(0);
DM.CDS_VEICULO.close;
ATIVABTN;
end;
end;

procedure TF_CadVeiculo1.btn_novoClick(Sender: TObject);
var
vID: integer;
begin
with SP_GEN_VEICULOS do
begin
Prepared := True;
ExecProc;
Prepared := False;
vID := ParamByName('ID').Value;
close;
end;
DM.CDS_VEICULO.Open;
DM.CDS_VEICULO.Append;
DM.CDS_VEICULO.FieldByName('ID').AsInteger := vID;
Desativabtn;
ativadbedit;
btn_gravar.SetFocus;
btn_foto1.Enabled := True;
btn_foto2.enabled := True;
btn_foto3.enabled := True;
btn_foto4.enabled := True;
btn_foto5.enabled := True;
btn_foto6.enabled := True;
btn_foto7.enabled := True;
btn_foto8.enabled := True;
end;


procedure TF_CadVeiculo1.btn_sairClick(Sender: TObject);
begin
Close;
end;

end.
Responder
×
+1 DevUP
Acesso diário, +1 DevUP
Parabéns, você está investindo na sua carreira