Fórum Retornar classe na função #456198
23/09/2013
0
Ex: function Pesquisar(Value:Integer):TClientes
Fiz dessa forma, mas se faço um teste como o abaixo,
if TClientes.Create(Self).Pesquisar(''1'').Codigo > 0 then ....
Sempre dá violação de acesso..
Devjunior
Curtir tópico
+ 0Posts
23/09/2013
Joel Rodrigues
Gostei + 0
23/09/2013
Devjunior
interface
uses
Data.DB, Data.Win.ADODB,System.SysUtils;
type
TCliente = class
private
FCodigo: integer;
FNome: string;
FCpfCgc: string;
procedure SetCodigo(const Value: integer);
procedure SetNome(const Value: string);
procedure SetCpfCgc(const Value: string);
public
property Codigo : integer read FCodigo write SetCodigo;
property Nome : string read FNome write SetNome;
property CpfCgc : string read FCpfCgc write SetCpfCgc;
function Pesquisar(Value:integer):TCliente;
end;
implementation
{ TCliente }
uses Unit1, Unit3;
function TCliente.Pesquisar(Value: integer): TCliente;
var
qry : TADOQuery;
begin
qry := TADOQuery.Create(nil);
qry.Connection := DataModule3.ADOConnection1;
qry.SQL.Text := 'select cliid, clinome, cliCpfCgc from cliente where cliid='+IntToStr(Value);
qry.Open;
if not qry.IsEmpty then
begin
FCodigo := qry.FieldByName('Cliid').Value;
FNome := qry.FieldByName('Clinome').Value;
FCpfCgc := qry.FieldByName('cliCpfCgc').Value;
end;
end;
procedure TCliente.SetCodigo(const Value: integer);
begin
FCodigo := Value;
end;
procedure TCliente.SetCpfCgc(const Value: string);
begin
FCpfCgc := Value;
end;
procedure TCliente.SetNome(const Value: string);
begin
FNome := Value;
end;
end.
Gostei + 0
23/09/2013
Joel Rodrigues
Gostei + 0
24/09/2013
Devjunior
Consegui implementar.
Gostei + 0
24/09/2013
Joel Rodrigues
Estou marcando o tópico como concluído.
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)