Como criar quot;efeitoquot; Click em Componente
Olá caros Colegas,
Olha é o seguinte,
Quero Adicionar um evento OnClick do Botões ligados ao componetes com suas respectivas propriedade.
Não sei explicar direito, mais vc vendo o q eu quero fazer vcs vão entender melhor.
Componente:
-------------------------------------------------------------------------------------
unit ControleBancoDados;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs, DB, StdCtrls;
type
TControleBancoDados = class(TComponent)
procedure BtPrimeiroClick(Sender: TObject);
procedure BtNovoClick(Sender: TObject);
procedure BtSalvarClick(Sender: TObject);
procedure BtCancelarClick(Sender: TObject);
procedure BtExcluirClick(Sender: TObject);
procedure BtEditarClick(Sender: TObject);
procedure BtUltimoClick(Sender: TObject);
procedure BtAnteriorClick(Sender: TObject);
procedure BtProximoClick(Sender: TObject);
private
fDataSource: TDataSource;
fBtPrimerio: TButtonControl;
fBtProximo : TButtonControl;
fBtAnterior: TButtonControl;
fBtUltimo : TButtonControl;
fBtSalvar : TButtonControl;
fBtCancelar: TButtonControl;
fBtExcluir : TButtonControl;
fBtNovo : TButtonControl;
fBtEditar : TButtonControl;
procedure setDataSource(Value: TDataSource);
Procedure StateChange(Sender: TObject);
protected
public
constructor Create(AOwner: TComponent);
published
property DataSource: TDataSource read fDataSource write fDataSource;
property BtPrimeiro: TButtonControl read fBtPrimerio write fBtPrimerio;
property BtProximo : TButtonControl read fBtProximo write fBtProximo;
property BtAnterior: TButtonControl read fBtAnterior write fBtAnterior;
property BtUltimo : TButtonControl read fBtUltimo write fBtUltimo;
property BtSalvar : TButtonControl read fBtSalvar write fBtSalvar;
property BtCancelar: TButtonControl read fBtCancelar write fBtCancelar;
property BtExcluir : TButtonControl read fBtExcluir write fBtExcluir;
property BtNovo : TButtonControl read fBtNovo write fBtNovo;
property BtEditar : TButtonControl read fBtEditar write fBtEditar;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents(´Christian´, [TControleBancoDados]);
end;
constructor TControleBancoDados.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
end;
///////////////////// Clicks dos Botões //////////////////////////////////
procedure TControleBancoDados.BtUltimoClick(Sender: TObject);
begin
inherited;
fDataSource.DataSet.Last;
end;
procedure TControleBancoDados.BtNovoClick(Sender: TObject);
begin
fDataSource.DataSet.Append;
end;
procedure TControleBancoDados.BtPrimeiroClick(Sender: TObject);
begin
fDataSource.DataSet.First;
end;
procedure TControleBancoDados.BtSalvarClick(Sender: TObject);
begin
fDataSource.DataSet.Post;
end;
procedure TControleBancoDados.BtCancelarClick(Sender: TObject);
begin
fDataSource.DataSet.Cancel;
end;
procedure TControleBancoDados.BtExcluirClick(Sender: TObject);
begin
fDataSource.DataSet.Delete;
end;
procedure TControleBancoDados.BtEditarClick(Sender: TObject);
begin
inherited;
fDataSource.DataSet.Edit;
end;
procedure TControleBancoDados.BtAnteriorClick(Sender: TObject);
begin
fDataSource.DataSet.Prior;
end;
procedure TControleBancoDados.BtProximoClick(Sender: TObject);
begin
inherited;
fDataSource.DataSet.Next;
end;
/////////////////////////////// FIM ///////////////////////////////
procedure TControleBancoDados.setDataSource(Value: TDataSource);
begin
fDataSource := Value;
if not Assigned(fDataSource) then
fDataSource := TDataSource.Create(Self);
fDataSource.DataSet := Value.DataSet;
fDataSource.AutoEdit := Value.AutoEdit;
fDataSource.OnStateChange := StateChange;
end;
Procedure TControleBancoDados.StateChange(Sender: TObject);
begin
if Assigned(BtPrimeiro) then
BtPrimeiro.Enabled := not (fDataSource.DataSet.IsEmpty) and
not fDataSource.DataSet.Bof and
(fDataSource.DataSet.State in [dsBrowse]);
if Assigned(BtProximo) then
BtProximo.Enabled := not (fDataSource.DataSet.IsEmpty) and
not fDataSource.DataSet.Eof and
(fDataSource.DataSet.State in [dsBrowse]);
if Assigned(BtAnterior) then
BtAnterior.Enabled := not (fDataSource.DataSet.IsEmpty) and
not fDataSource.DataSet.Bof and
(fDataSource.DataSet.State in [dsBrowse]);
if Assigned(BtUltimo) then
BtUltimo.Enabled := not (fDataSource.DataSet.IsEmpty) and
not fDataSource.DataSet.Eof and
(fDataSource.DataSet.State in [dsBrowse]);
if Assigned(BtNovo) then
BtNovo.Enabled := (fDataSource.DataSet.State in [dsBrowse]) and
not (fDataSource.DataSet.State in [dsEdit, dsInsert]);
if Assigned(BtSalvar) then
BtSalvar.Enabled := not BtNovo.Enabled;
if Assigned(BtCancelar) then
BtCancelar.Enabled := BtSalvar.Enabled;
if Assigned(BtEditar) then
BtEditar.Enabled := BtNovo.Enabled and
not (fDataSource.DataSet.Eof and fDataSource.DataSet.Bof);
if Assigned(BtExcluir) then
BtExcluir.Enabled := BtEditar.Enabled;
end;
end.
-------------------------------------------------------------------------------------
Flw,
t++
Abraços,
Christian.
Olha é o seguinte,
Quero Adicionar um evento OnClick do Botões ligados ao componetes com suas respectivas propriedade.
Não sei explicar direito, mais vc vendo o q eu quero fazer vcs vão entender melhor.
Componente:
-------------------------------------------------------------------------------------
unit ControleBancoDados;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs, DB, StdCtrls;
type
TControleBancoDados = class(TComponent)
procedure BtPrimeiroClick(Sender: TObject);
procedure BtNovoClick(Sender: TObject);
procedure BtSalvarClick(Sender: TObject);
procedure BtCancelarClick(Sender: TObject);
procedure BtExcluirClick(Sender: TObject);
procedure BtEditarClick(Sender: TObject);
procedure BtUltimoClick(Sender: TObject);
procedure BtAnteriorClick(Sender: TObject);
procedure BtProximoClick(Sender: TObject);
private
fDataSource: TDataSource;
fBtPrimerio: TButtonControl;
fBtProximo : TButtonControl;
fBtAnterior: TButtonControl;
fBtUltimo : TButtonControl;
fBtSalvar : TButtonControl;
fBtCancelar: TButtonControl;
fBtExcluir : TButtonControl;
fBtNovo : TButtonControl;
fBtEditar : TButtonControl;
procedure setDataSource(Value: TDataSource);
Procedure StateChange(Sender: TObject);
protected
public
constructor Create(AOwner: TComponent);
published
property DataSource: TDataSource read fDataSource write fDataSource;
property BtPrimeiro: TButtonControl read fBtPrimerio write fBtPrimerio;
property BtProximo : TButtonControl read fBtProximo write fBtProximo;
property BtAnterior: TButtonControl read fBtAnterior write fBtAnterior;
property BtUltimo : TButtonControl read fBtUltimo write fBtUltimo;
property BtSalvar : TButtonControl read fBtSalvar write fBtSalvar;
property BtCancelar: TButtonControl read fBtCancelar write fBtCancelar;
property BtExcluir : TButtonControl read fBtExcluir write fBtExcluir;
property BtNovo : TButtonControl read fBtNovo write fBtNovo;
property BtEditar : TButtonControl read fBtEditar write fBtEditar;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents(´Christian´, [TControleBancoDados]);
end;
constructor TControleBancoDados.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
end;
///////////////////// Clicks dos Botões //////////////////////////////////
procedure TControleBancoDados.BtUltimoClick(Sender: TObject);
begin
inherited;
fDataSource.DataSet.Last;
end;
procedure TControleBancoDados.BtNovoClick(Sender: TObject);
begin
fDataSource.DataSet.Append;
end;
procedure TControleBancoDados.BtPrimeiroClick(Sender: TObject);
begin
fDataSource.DataSet.First;
end;
procedure TControleBancoDados.BtSalvarClick(Sender: TObject);
begin
fDataSource.DataSet.Post;
end;
procedure TControleBancoDados.BtCancelarClick(Sender: TObject);
begin
fDataSource.DataSet.Cancel;
end;
procedure TControleBancoDados.BtExcluirClick(Sender: TObject);
begin
fDataSource.DataSet.Delete;
end;
procedure TControleBancoDados.BtEditarClick(Sender: TObject);
begin
inherited;
fDataSource.DataSet.Edit;
end;
procedure TControleBancoDados.BtAnteriorClick(Sender: TObject);
begin
fDataSource.DataSet.Prior;
end;
procedure TControleBancoDados.BtProximoClick(Sender: TObject);
begin
inherited;
fDataSource.DataSet.Next;
end;
/////////////////////////////// FIM ///////////////////////////////
procedure TControleBancoDados.setDataSource(Value: TDataSource);
begin
fDataSource := Value;
if not Assigned(fDataSource) then
fDataSource := TDataSource.Create(Self);
fDataSource.DataSet := Value.DataSet;
fDataSource.AutoEdit := Value.AutoEdit;
fDataSource.OnStateChange := StateChange;
end;
Procedure TControleBancoDados.StateChange(Sender: TObject);
begin
if Assigned(BtPrimeiro) then
BtPrimeiro.Enabled := not (fDataSource.DataSet.IsEmpty) and
not fDataSource.DataSet.Bof and
(fDataSource.DataSet.State in [dsBrowse]);
if Assigned(BtProximo) then
BtProximo.Enabled := not (fDataSource.DataSet.IsEmpty) and
not fDataSource.DataSet.Eof and
(fDataSource.DataSet.State in [dsBrowse]);
if Assigned(BtAnterior) then
BtAnterior.Enabled := not (fDataSource.DataSet.IsEmpty) and
not fDataSource.DataSet.Bof and
(fDataSource.DataSet.State in [dsBrowse]);
if Assigned(BtUltimo) then
BtUltimo.Enabled := not (fDataSource.DataSet.IsEmpty) and
not fDataSource.DataSet.Eof and
(fDataSource.DataSet.State in [dsBrowse]);
if Assigned(BtNovo) then
BtNovo.Enabled := (fDataSource.DataSet.State in [dsBrowse]) and
not (fDataSource.DataSet.State in [dsEdit, dsInsert]);
if Assigned(BtSalvar) then
BtSalvar.Enabled := not BtNovo.Enabled;
if Assigned(BtCancelar) then
BtCancelar.Enabled := BtSalvar.Enabled;
if Assigned(BtEditar) then
BtEditar.Enabled := BtNovo.Enabled and
not (fDataSource.DataSet.Eof and fDataSource.DataSet.Bof);
if Assigned(BtExcluir) then
BtExcluir.Enabled := BtEditar.Enabled;
end;
end.
-------------------------------------------------------------------------------------
Flw,
t++
Abraços,
Christian.
Christian_adriano
Curtidas 0
Respostas
Gurc
18/11/2004
Imagino que o que você quer seja o seguinte:
Gustavo Royer Chaurais
fBtPrimerio.OnClick := BtPrimeiroClick;
Gustavo Royer Chaurais
GOSTEI 0
Christian_adriano
18/11/2004
Valeu....
vou tentar implementar.
[]´s.
Christian
vou tentar implementar.
[]´s.
Christian
GOSTEI 0
Gurc
18/11/2004
Certo, qualquer dúvida estamos aí.
Gustavo Royer Chaurais
Gustavo Royer Chaurais
GOSTEI 0