Ir para conteúdo
  • Cadastre-se

dev botao

OOP - Ajuda


Ver Solução Respondido por eneias.carvalho,
  • Este tópico foi criado há 4248 dias atrás.
  • Talvez seja melhor você criar um NOVO TÓPICO do que postar uma resposta aqui.

Recommended Posts

Pessoa não sei se este seria o melhor canal para tirar tal dúvida, más desde a "morte" do orkut, desconheço um bom canal de dúvidas Delphi, caso alguem possa ajudar e indicar fico grato, de qualquer segue minha dúvida, estou estudando orientação à objetos e desde o inicio senti que o mesmo pode ser bem trabalhoso, más isso não vem ao caso, a questão é, estou criando um aplicativo para gerar minhas classes(Negócios e Persistência), ocorre que não sei se estou fazendo da maneira correta, na realidade acredito que eu esteja fazendo da maneira errada, do contrario não estaria com problema, um rápido resumo do programa, o mesmo se conecta há um banco mysql, seleciono uma tabela e o sistema se encarrega de gerar os .PAS, porem ao trabalhar com as classes geradas está sendo retornado erro na criação dos componentes, por exemplo, trabalho com o Zeos, sendo assim em minha classe de persistência no Create da mesma eu crio meu componente, porem está sendo retornado um erro, já debuguei porem não consegui encontrar nada que possa indicar o erro, por este motivo imagino que o erro de fato está em minha lógica, se alguem puder ajudar, segue códigos:

obs: O erro ocorre na camada de persistência, no Create do componente ZQuery, outro ponto que gostaria de receber alguma orientação é de que forma posso trabalhar melhor estas camadas, pois na camada de negócios acabo tendo que passar o componente de conexão ao banco de dados.

classFornecedoresDAO:

Unit classFornecedoresDAO;


interface


uses

  classFornecedores, DB, ZAbstractRODataset, ZAbstractDataset, ZDataset, Variants, Classes, Controls, ZConnection;


type

  TFornecedoresDAO = class

    private

      FSQLFornecedores                  : TZQuery;


    public

      constructor Create(Conn : TZConnection);

      destructor Destroy;


      function Insert(oFornecedores : TFornecedores) : Boolean;

end;


implementation


{ TFornecedoresDAO }


constructor TFornecedoresDAO.Create(Conn: TZConnection);

begin

  inherited Create;

  FSQLFornecedores                              :=  TZQuery.Create(nil);

  FSQLFornecedores.Connection                   :=  Conn;

end;


destructor TFornecedoresDAO.Destroy;

begin

  inherited;

end;


function TFornecedoresDAO.Insert(oFornecedores : TFornecedores) : Boolean;

begin

  Result                                        :=  False;

  with FSQLFornecedores do

  begin

    Close;

    SQL.Clear;

    SQL.Add('Select * From Fornecedores');

    SQL.Add('Where(Codigo = :Codigo)');

    Open;

    Insert;

    FieldByName('Tipo').Value                   :=  oFornecedores.Tipo;

    FieldByName('Cnpj').Value                   :=  oFornecedores.Cnpj;

    FieldByName('Ie').Value                     :=  oFornecedores.Ie;

    FieldByName('Im').Value                     :=  oFornecedores.Im;

    FieldByName('Cpf').Value                    :=  oFornecedores.Cpf;

    FieldByName('Rg').Value                     :=  oFornecedores.Rg;

    FieldByName('Nome').Value                   :=  oFornecedores.Nome;

    FieldByName('Endereco').Value               :=  oFornecedores.Endereco;

    FieldByName('Bairro').Value                 :=  oFornecedores.Bairro;

    FieldByName('Cidade').Value                 :=  oFornecedores.Cidade;

    FieldByName('Estado').Value                 :=  oFornecedores.Estado;

    FieldByName('Cep').Value                    :=  oFornecedores.Cep;

    FieldByName('Fone1').Value                  :=  oFornecedores.Fone1;

    FieldByName('Fone2').Value                  :=  oFornecedores.Fone2;

    FieldByName('Fone3').Value                  :=  oFornecedores.Fone3;

    FieldByName('Email').Value                  :=  oFornecedores.Email;

    FieldByName('Homepage').Value               :=  oFornecedores.Homepage;

    FieldByName('Obs').Value                    :=  oFornecedores.Obs;

    FieldByName('Contato').Value                :=  oFornecedores.Contato;

    FieldByName('Empresa').Value                :=  oFornecedores.Empresa;

    FieldByName('Fantasia').Value               :=  oFornecedores.Fantasia;

    FieldByName('Negativacao').Value            :=  oFornecedores.Negativacao;

    FieldByName('Codmunicipio').Value           :=  oFornecedores.Codmunicipio;

    FieldByName('Contabil').Value               :=  oFornecedores.Contabil;

    FieldByName('Dtnasc').Value                 :=  oFornecedores.Dtnasc;

    Post;

    Result                                      :=  True;

  end;

end;


end.
classFornecedores:
Unit classFornecedores;


interface


uses

  Variants, Classes, Controls, ZConnection;


type

  TFornecedores = class

    private

      FCodigo                           : Integer;

      FTipo                             : String;

      FCnpj                             : String;

      FIe                               : String;

      FIm                               : String;

      FCpf                              : String;

      FRg                               : String;

      FNome                             : String;

      FEndereco                         : String;

      FBairro                           : String;

      FCidade                           : String;

      FEstado                           : String;

      FCep                              : String;

      FFone1                            : String;

      FFone2                            : String;

      FFone3                            : String;

      FEmail                            : String;

      FHomepage                         : String;

      FObs                              : String;

      FContato                          : String;

      FEmpresa                          : Integer;

      FFantasia                         : String;

      FNegativacao                      : String;

      FCodmunicipio                     : String;

      FContabil                         : Integer;

      FDtnasc                           : TDate;

      Conexao                           : TZConnection;


      procedure SetCodigo(const Value : Integer);

      procedure SetTipo(const Value : String);

      procedure SetCnpj(const Value : String);

      procedure SetIe(const Value : String);

      procedure SetIm(const Value : String);

      procedure SetCpf(const Value : String);

      procedure SetRg(const Value : String);

      procedure SetNome(const Value : String);

      procedure SetEndereco(const Value : String);

      procedure SetBairro(const Value : String);

      procedure SetCidade(const Value : String);

      procedure SetEstado(const Value : String);

      procedure SetCep(const Value : String);

      procedure SetFone1(const Value : String);

      procedure SetFone2(const Value : String);

      procedure SetFone3(const Value : String);

      procedure SetEmail(const Value : String);

      procedure SetHomepage(const Value : String);

      procedure SetObs(const Value : String);

      procedure SetContato(const Value : String);

      procedure SetEmpresa(const Value : Integer);

      procedure SetFantasia(const Value : String);

      procedure SetNegativacao(const Value : String);

      procedure SetCodmunicipio(const Value : String);

      procedure SetContabil(const Value : Integer);

      procedure SetDtnasc(const Value : TDate);

    public

      constructor Create(Conn : TZConnection);

      destructor Destroy;


      property Codigo                   : Integer      read  FCodigo              write  SetCodigo;

      property Tipo                     : String       read  FTipo                write  SetTipo;

      property Cnpj                     : String       read  FCnpj                write  SetCnpj;

      property Ie                       : String       read  FIe                  write  SetIe;

      property Im                       : String       read  FIm                  write  SetIm;

      property Cpf                      : String       read  FCpf                 write  SetCpf;

      property Rg                       : String       read  FRg                  write  SetRg;

      property Nome                     : String       read  FNome                write  SetNome;

      property Endereco                 : String       read  FEndereco            write  SetEndereco;

      property Bairro                   : String       read  FBairro              write  SetBairro;

      property Cidade                   : String       read  FCidade              write  SetCidade;

      property Estado                   : String       read  FEstado              write  SetEstado;

      property Cep                      : String       read  FCep                 write  SetCep;

      property Fone1                    : String       read  FFone1               write  SetFone1;

      property Fone2                    : String       read  FFone2               write  SetFone2;

      property Fone3                    : String       read  FFone3               write  SetFone3;

      property Email                    : String       read  FEmail               write  SetEmail;

      property Homepage                 : String       read  FHomepage            write  SetHomepage;

      property Obs                      : String       read  FObs                 write  SetObs;

      property Contato                  : String       read  FContato             write  SetContato;

      property Empresa                  : Integer      read  FEmpresa             write  SetEmpresa;

      property Fantasia                 : String       read  FFantasia            write  SetFantasia;

      property Negativacao              : String       read  FNegativacao         write  SetNegativacao;

      property Codmunicipio             : String       read  FCodmunicipio        write  SetCodmunicipio;

      property Contabil                 : Integer      read  FContabil            write  SetContabil;

      property Dtnasc                   : TDate        read  FDtnasc              write  SetDtnasc;


      function Insert : Boolean;

end;


implementation


uses

  classFornecedoresDAO;


{ TFornecedores }


constructor TFornecedores.Create(Conn : TZConnection);

begin

  inherited Create;

  Conexao                                       :=  Conn

end;


destructor TFornecedores.Destroy;

begin

  inherited;

end;


procedure TFornecedores.SetCodigo(const Value : Integer);

begin

   FCodigo                                       :=  Value;

end;


procedure TFornecedores.SetTipo(const Value : String);

begin

   FTipo                                         :=  Value;

end;


procedure TFornecedores.SetCnpj(const Value : String);

begin

   FCnpj                                         :=  Value;

end;


procedure TFornecedores.SetIe(const Value : String);

begin

   FIe                                           :=  Value;

end;


procedure TFornecedores.SetIm(const Value : String);

begin

   FIm                                           :=  Value;

end;


procedure TFornecedores.SetCpf(const Value : String);

begin

   FCpf                                          :=  Value;

end;


procedure TFornecedores.SetRg(const Value : String);

begin

   FRg                                           :=  Value;

end;


procedure TFornecedores.SetNome(const Value : String);

begin

   FNome                                         :=  Value;

end;


procedure TFornecedores.SetEndereco(const Value : String);

begin

   FEndereco                                     :=  Value;

end;


procedure TFornecedores.SetBairro(const Value : String);

begin

   FBairro                                       :=  Value;

end;


procedure TFornecedores.SetCidade(const Value : String);

begin

   FCidade                                       :=  Value;

end;


procedure TFornecedores.SetEstado(const Value : String);

begin

   FEstado                                       :=  Value;

end;


procedure TFornecedores.SetCep(const Value : String);

begin

   FCep                                          :=  Value;

end;


procedure TFornecedores.SetFone1(const Value : String);

begin

   FFone1                                        :=  Value;

end;


procedure TFornecedores.SetFone2(const Value : String);

begin

   FFone2                                        :=  Value;

end;


procedure TFornecedores.SetFone3(const Value : String);

begin

   FFone3                                        :=  Value;

end;


procedure TFornecedores.SetEmail(const Value : String);

begin

   FEmail                                        :=  Value;

end;


procedure TFornecedores.SetHomepage(const Value : String);

begin

   FHomepage                                     :=  Value;

end;


procedure TFornecedores.SetObs(const Value : String);

begin

   FObs                                          :=  Value;

end;


procedure TFornecedores.SetContato(const Value : String);

begin

   FContato                                      :=  Value;

end;


procedure TFornecedores.SetEmpresa(const Value : Integer);

begin

   FEmpresa                                      :=  Value;

end;


procedure TFornecedores.SetFantasia(const Value : String);

begin

   FFantasia                                     :=  Value;

end;


procedure TFornecedores.SetNegativacao(const Value : String);

begin

   FNegativacao                                  :=  Value;

end;


procedure TFornecedores.SetCodmunicipio(const Value : String);

begin

   FCodmunicipio                                 :=  Value;

end;


procedure TFornecedores.SetContabil(const Value : Integer);

begin

   FContabil                                     :=  Value;

end;


procedure TFornecedores.SetDtnasc(const Value : TDate);

begin

   FDtnasc                                       :=  Value;

end;


function TFornecedores.Insert : Boolean;

  var

    fDAO : TFornecedoresDAO;

begin

  fDAO.Create(Conexao);

  Result                                        :=  fDAO.Insert(Self);

end;


end.
Camada de Apresentação:
unit Unit1;


interface


uses

  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

  Dialogs, ZConnection, StdCtrls;


type

  TForm1 = class(TForm)

    ZConnection1: TZConnection;

    Button1: TButton;

    procedure Button1Click(Sender: TObject);

  private

    { Private declarations }

  public

    { Public declarations }

  end;


var

  Form1: TForm1;


implementation


uses classFornecedores;


{$R *.dfm}


procedure TForm1.Button1Click(Sender: TObject);

  var

    oFornecedor : TFornecedores;

begin

  oFornecedor.Create(ZConnection1);

  oFornecedor.Nome                              :=  'Eneias';

  oFornecedor.Insert;

end;


end.

Link para o comentário
Compartilhar em outros sites

  • Consultores

Se possível use mais parágrafos no seu texto.

Voltando à sua pergunta, OOP ou ORM?

[]'s

Consultor SAC ACBr

Elton
Profissionalize o ACBr na sua empresa, conheça o ACBr Pro.

Projeto ACBr     Telefone:(15) 2105-0750 WhatsApp(15)99790-2976.

Um engenheiro de Controle de Qualidade(QA) entra num bar. Pede uma cerveja. Pede zero cervejas.
Pede 99999999 cervejas. Pede -1 cervejas. Pede um jacaré. Pede asdfdhklçkh.
Link para o comentário
Compartilhar em outros sites

Pesso desculpas pela forma direta com a que escrevi, irei me policiar para isso, em seguida seria meio que uma mistura dos dois, pois programo em Delphi 7 e o mesmo não possui nenhum framework ORM(pelo menos desconheço), então resolvi criar um por mais simples que seja é claro.

O mesmo faz basicamente o que descrevi, informo à aplicação qual o componente de conexão à dados que irei utilizar(Zeos ou UniDAC), em seguida entro com os dados de conexão(Host, User, Pass, Port e DB), por fim seleciono uma tabela e mando gerar, a aplicação então salva dois arquivos, um referente à negócios(classNomeDaTabela.pas) e outro referente à persistência(classNomeDaTabelaDAO.pas).

Link para o comentário
Compartilhar em outros sites

  • Consultores

Texto escrito como fez, é muito confuso. Veja a diferença:

Pesso desculpas pela forma direta com a que escrevi. Irei me policiar para isso.

Em seguida seria meio que uma mistura dos dois, pois programo em Delphi 7 e o mesmo não possui nenhum framework ORM(pelo menos desconheço). Então resolvi criar um, por mais simples que seja, é claro.

O mesmo faz basicamente o que descrevi:

1) Informo à aplicação qual o componente de conexão à dados que irei utilizar(Zeos ou UniDAC).

2) Em seguida entro com os dados de conexão(Host, User, Pass, Port e DB).

3) Por fim seleciono uma tabela e mando gerar.

4) A aplicação então salva dois arquivos, um referente à negócios(classNomeDaTabela.pas) e outro referente à persistência(classNomeDaTabelaDAO.pas).

Quanto a frameWorks ORM, pelo visto existem um bom número. Veja aí http://stackoverflow.com/questions/422426/orm-for-delphi-win32.

No mais estou movendo sua dúvida para área correta.

[]'s

Consultor SAC ACBr

Elton
Profissionalize o ACBr na sua empresa, conheça o ACBr Pro.

Projeto ACBr     Telefone:(15) 2105-0750 WhatsApp(15)99790-2976.

Um engenheiro de Controle de Qualidade(QA) entra num bar. Pede uma cerveja. Pede zero cervejas.
Pede 99999999 cervejas. Pede -1 cervejas. Pede um jacaré. Pede asdfdhklçkh.
Link para o comentário
Compartilhar em outros sites

  • Este tópico foi criado há 4248 dias atrás.
  • Talvez seja melhor você criar um NOVO TÓPICO do que postar uma resposta aqui.

Crie uma conta ou entre para comentar

Você precisar ser um membro para fazer um comentário

Criar uma conta

Crie uma nova conta em nossa comunidade. É fácil!

Crie uma nova conta

Entrar

Já tem uma conta? Faça o login.

Entrar Agora
×
×
  • Criar Novo...

Informação Importante

Colocamos cookies em seu dispositivo para ajudar a tornar este site melhor. Você pode ajustar suas configurações de cookies, caso contrário, assumiremos que você está bem para continuar.

The popup will be closed in 10 segundos...