como chamar uma função no botão e passar paramentros num componente label e text

14/02/2010

0

Ola a todos !!! veja este exemplo EM DELPHI 7

unit UBancoDados;

interface

uses ADODB,DB;

type

TCadPrinc=class

private
cnx:TADOConnection;
cadQry:TADOQuery;
Ds:TDataSource;

public

constructor create;overload;
destructor destroy;overload;
Function FazerConexao:boolean;
Function Incluir_Dados(cod:integer;nom:string):boolean;
Function Excluir_Dados(cod:integer;nom:string):boolean;
Function Alterar_Dados(cod:integer;nom:string):boolean;

end;

implementation

constructor TCadprinc.create;
begin
inherited create;
cnx:= TADOConnection.Create(nil);
ds:= TDataSource.Create(nil);
cadqry:= TADOQUERY.Create(nil);
end;
destructor TCadprinc.destroy;
begin
cnx.Destroy;
ds.Destroy;
cadqry.Destroy;
inherited destroy;
end;

function TCadPrinc.FazerConexao: boolean;
begin
cnx.Connected :=true;
cnx.ConnectionString :='provider=sqloledb.1;integrated security = sspi;persist security info = false;intial catalog = agenda; data sorce = fabio';
cnx.LoginPrompt :=true;
ds.DataSet := cadqry;
cadqry.Active := true;
cadqry.Connection := Cnx;
cadqry.SQL.Add('select*from tbcad where codigo=:wcod and nome=:wnom');
end;

function TCadPrinc.Incluir_Dados(cod:integer;nom:string):bo olean;
begin
with cadqry do
begin
try
close;
sql.Clear;
sql.Add('insert into tbcad(codigo,nome) values(:wcod,:wnom)');
parameters[0].Value :=cod;
parameters[1].Value:=nom;
execsql;
except
end;
end;
end;

function TCadPrinc.Excluir_Dados(cod:integer;nom:string):bo olean;
begin
with cadqry do
begin
try
close;
sql.Clear;
sql.Add('delete from tbcad where codigo =:wcod and nome=:wnom');
parameters[0].Value :=cod;
parameters[1].Value:=nom;
execsql;
except
end;
end;
end;

function TCadPrinc.Alterar_Dados(cod:integer;nom:string):bo olean;
begin
with cadqry do
begin
try
close;
sql.Clear;
sql.Add('update tbcad set codigo=:wcod and nome=:wnom');
parameters[0].Value :=cod;
parameters[1].Value:=nom;
execsql;
except
end;
end;
end;

end.

E AGORA TENHO OUTRO FORM DE CADASTRO QUE POSSUI 3 botões, INCLUIR, EXCLUIR E ALTERAR E QUERIA CHAMAR AS SEGUINTES FUNÇÕES INCLUIR_DADOS,EXCLUIR_DADOS E ALTERAR_DADOS PARA DENTRO DOS BOTÕES E PASSAR OS PARAMETROS PARA DENTRO DE UMA LABEL (LBCOD.CAPTION) E TEXT (TXTNOME.TEXT) PEDINDO PARA VERIFICAR SE NAO HA REPETIÇÕES DE INCLUSÃO DE DADOS.

OK MUITO OBRIGADO
Fabio Pellegrini

Fabio Pellegrini

Responder

Posts

14/02/2010

Fabio Pellegrini

procedure Tfrmcad.BtnInclClick(Sender: TObject);
begin
if objcad.Incluir_Dados(wcod;wnom) then / está havendo erro nesta linda - [error] ucad.pas(58): undeclared identifier: 'wcod'/
begin
lbcodigo.Caption := wcod;
txtnome.Text := wnom;
end;
end;
end.
Responder

Assista grátis a nossa aula inaugural

Assitir aula

Saiba por que programar é uma questão de
sobrevivência e como aprender sem riscos

Assistir agora

Utilizamos cookies para fornecer uma melhor experiência para nossos usuários, consulte nossa política de privacidade.

Aceitar