Exemplo Infra

8 views
Skip to first unread message

Daniel Sobrinho Laporte

unread,
Mar 26, 2009, 9:20:32 AM3/26/09
to infra...@googlegroups.com
Bom dia Galera,

Gostaria de criar um exemplo simples utilizando o Infra, até para podemos expor aqui para a lista, porém, não sei por onde começar, como inicio a criação de um exemplo simples no Infra ? Por onde começo ? Qualquer ajuda será muitissimo bem vinda.

Abrçaos,
Daniel

Marcos Barreto

unread,
Mar 26, 2009, 12:08:09 PM3/26/09
to infra...@googlegroups.com
Gostaria de criar um exemplo simples utilizando o Infra, até para podemos expor aqui para a lista, porém, não sei por onde começar, como inicio a criação de um exemplo simples no Infra ? Por onde começo ? Qualquer ajuda será muitissimo bem vinda.

- O passo inicial é criar seu modelo orientado a objeto, se você nao tem alguma modelagem especifica para construir este primeiro demo eu vou sugerir um modelo bem simples e nós iremos ir evoluindo com o tempo.

Classe: Cliente
Atributos: Id, Nome, Datanascimento, Telefone, Endereco, Cidade, Ativo

Classe: Cidade
Atributos: Id, Nome, Estado

O cliente é ligado a uma cidade através do atributo Cliente.Cidade (acho que nem precisava falar isso, mas tudo bem)

- O próximo passo é codificar estas classes em 2 units. A primeira unit teria interfaces, a segunda teria as classes implmentando as interfaces. Para criar isso no infra sugiro que dê uma olhada aqui:

A unit abaixo mostra uma classe Account, vc deverá criar uma unit parecida com ela com as classes citadas acima
http://code.google.com/p/infra/source/browse/branches/persistence/src/UnitTests/InfraOPF/PersistenceModel.pas

A unit abaixo contem a interface IAccount, vc deverá criar uma unit parecida com ela com interfaces das classes citadas acima.
http://code.google.com/p/infra/source/browse/branches/persistence/src/UnitTests/InfraOPF/PersistenceModelIntf.pas

Quando projeto uma aplicação no Infra sempre começo pelas interfaces, mas para como isto aqui é só um demo e já estamos definindo o modelo, isso nao faz muita diferença.

Pronto assim que estas units estiverem prontas vc nos mostra aqui que agente avalia e corrige o que for necessário para podermos passar aos passos seguintes. Vamos montar uma telinha para apresentar um objeto Cliente, e depois vamos fazer isso ser gravado em um banco de dados.

José Henrique

unread,
Mar 27, 2009, 10:19:16 AM3/27/09
to Infra - Integrated Frameworks
Senhores, quero colaborar para poder aprender mais sobre o Infra, o
que eu posso fazer o que já tem feito para termos um exemplo de
persistência ?




On 26 mar, 13:08, Marcos Barreto <mrbar2...@gmail.com> wrote:
> > Gostaria de criar um exemplo simples utilizando o Infra, até para podemos
> > expor aqui para a lista, porém, não sei por onde começar, como inicio a
> > criação de um exemplo simples no Infra ? Por onde começo ? Qualquer ajuda
> > será muitissimo bem vinda.
>
> - O passo inicial é criar seu modelo orientado a objeto, se você nao tem
> alguma modelagem especifica para construir este primeiro demo eu vou sugerir
> um modelo bem simples e nós iremos ir evoluindo com o tempo.
>
> Classe: Cliente
> Atributos: Id, Nome, Datanascimento, Telefone, Endereco, Cidade, Ativo
>
> Classe: Cidade
> Atributos: Id, Nome, Estado
>
> O cliente é ligado a uma cidade através do atributo Cliente.Cidade (acho que
> nem precisava falar isso, mas tudo bem)
>
> - O próximo passo é codificar estas classes em 2 units. A primeira unit
> teria interfaces, a segunda teria as classes implmentando as interfaces.
> Para criar isso no infra sugiro que dê uma olhada aqui:
>
> A unit abaixo mostra uma classe Account, vc deverá criar uma unit parecida
> com ela com as classes citadas acimahttp://code.google.com/p/infra/source/browse/branches/persistence/src...
>
> A unit abaixo contem a interface IAccount, vc deverá criar uma unit parecida
> com ela com interfaces das classes citadas acima.http://code.google.com/p/infra/source/browse/branches/persistence/src...

gmail

unread,
Mar 27, 2009, 9:44:12 AM3/27/09
to infra...@googlegroups.com
Posso criar o banco no Firebird???

Marcos George

unread,
Mar 27, 2009, 11:07:44 AM3/27/09
to infra...@googlegroups.com
Vocês já deram uma olhada nos testes unitários da persistência? Eles formam uma ótima base pra quem está começando. E funciona!

Att
Marcos George



 

From: diretr...@gmail.com
To: infra...@googlegroups.com
Subject: [Infra 625] Re: Exemplo Infra
Date: Fri, 27 Mar 2009 10:44:12 -0300
<BR

José Henrique

unread,
Mar 27, 2009, 11:52:02 AM3/27/09
to Infra - Integrated Frameworks
Ok criei o exemplo da classe de cliente, como faço para mandar os
códigos para saber se fiz corretamente ? Mando aki pelo Fórum mesmo ?
Se estiver correta a implementação farei a outra classe tudo bem ?

estou no aguardo.

obrigado !!!

José Henrique

unread,
Mar 27, 2009, 11:58:24 AM3/27/09
to Infra - Integrated Frameworks
Ótimo !!

Marcos Barreto

unread,
Mar 27, 2009, 1:09:14 PM3/27/09
to infra...@googlegroups.com
sim pode criar a base de dados

Marcos Barreto

unread,
Mar 27, 2009, 1:10:27 PM3/27/09
to infra...@googlegroups.com
Você podem ir colocando as classes, scripts de banco, etc. e agente vai dizendo os próximos passos.

José Henrique

unread,
Mar 27, 2009, 2:25:00 PM3/27/09
to Infra - Integrated Frameworks
Vou fazer vários posts para nao confundir tudo em um só (já ficou
confuso né!?).

Aqui eu fiz a interface de cliente; por favor me indiquem se algo nao
estiver de acordo!

[quote]

unit u_ClienteModelIntf;

interface

uses
InfraValueTypeIntf;

type

ICliente = interface (IInfraObject)
['{FA3F5E23-435E-44FA-A54C-CFCEC5D4B189}']
function GetID : IInfraInteger;
procedure SetID(val : IInfraInteger);
function GetNome : IInfraString;
procedure SetNome(val : IInfraString);
function GetDatanascimento : IInfraDateTime;
procedure SetDatanascimento(val : IInfraDateTime);
function GetNomeMae : IInfraString;
procedure SetNomeMae(val : IInfraString);
function GetTelefone : IInfraString;
procedure SetTelefone(val : IInfraString);
function GetAtivo : IInfraString;
procedure SetAtivo(val : IInfraString);
function GetEndereco : IInfraString;
procedure SetEndereco(val : IInfraString);
function GetCidade : IInfraInteger;
procedure SetCidade(val : IInfraInteger);

property ID : IInfraInteger read GetID write SetID;
property Nome : IInfraString read GetNome write SetNome;
property NomeMae : IInfraString read GetNomeMae write SetNomeMae;
property Datanascimento : IInfraDateTime read GetDatanascimento
write SetDatanascimento;
property Telefone : IInfraString read GetTelefone write
SetTelefone;
property Cidade : IInfraInteger read GetCidade write SetCidade;
property Ativo : IInfraString read GetAtivo write SetAtivo;
property Endereco : IInfraString read GetEndereco write
SetEndereco;
end;



implementation

end.

[/quote]

José Henrique

unread,
Mar 27, 2009, 2:26:16 PM3/27/09
to Infra - Integrated Frameworks
Agora a classe Model de cliente

[quote]

unit u_ClienteModel;

interface

uses
InfraValueTypeIntf,
InfraValueType,
InfraCommonIntf,
u_ClienteModelIntf;

type
TCliente = class(TInfraObject, ICliente)
private
FID:IInfraInteger;
FNome:IInfraString;
FNascimento:IInfraDateTime;
FNomeMae:IInfraString;
FTelefone:IInfraString;
FEndereco:IInfraString;
FAtivo:IInfraString;
FCidade:IInfraInteger;
protected
function GetID : IInfraInteger;
procedure SetID(val : IInfraInteger);
function GetDataNascimento : IInfraDateTime;
procedure SetDataNascimento(val : IInfraDateTime);
function GetNomeMae : IInfraString;
procedure SetNomeMae(val : IInfraString);
function GetTelefone : IInfraString;
procedure SetTelefone(val : IInfraString);
function GetNome : IInfraString;
procedure SetNome(val : IInfraString);
function GetEndereco : IInfraString;
procedure SetEndereco(val : IInfraString);
function GetAtivo : IInfraString;
procedure SetAtivo(val : IInfraString);
function GetCidade : IInfraInteger;
procedure SetCidade(val : IInfraInteger);
{property's }
property ID : IInfraInteger read GetID write SetID;
property Nome : IInfraString read GetNome write SetNome;
property NomeMae : IInfraString read GetNomeMae write SetNomeMae;
property Datanascimento : IInfraDateTime read GetDatanascimento
write SetDatanascimento;
property Telefone : IInfraString read GetTelefone write
SetTelefone;
property Cidade : IInfraInteger read GetCidade write SetCidade;
property Ativo : IInfraString read GetAtivo write SetAtivo;
property Endereco : IInfraString read GetEndereco write
SetEndereco;
public
procedure InfraInitInstance;override;
end;


implementation

procedure TCliente.InfraInitInstance;
begin
inherited;
FID := AddProperty('ID') as IInfraInteger;
FNascimento := AddProperty('Nascimento') as IInfraDateTime;
FNome := AddProperty('Nome') as IInfraString;
FNomeMae := AddProperty('NomeMae') as IInfraString;
FTelefone := AddProperty('Telefone') as IInfraString;
FCidade := AddProperty('Cidade') as IInfraInteger;
FAtivo := AddProperty('Ativo') as IInfraString;
FEndereco := AddProperty('Endereco') as IInfraString;
end;

function TCliente.GetEndereco: IInfraString;
begin
Result:= FEndereco;
end;

function TCliente.GetID: IInfraInteger;
begin
Result:=FID;
end;

procedure TCliente.SetID(val : IInfraInteger);
begin
Fid := val;
end;

function TCliente.GetAtivo: IInfraString;
begin
Result:=FAtivo;
end;

function TCliente.GetCidade: IInfraInteger;
begin
Result := FCidade;
end;

function TCliente.GetDataNascimento: IInfraDateTime;
begin
Result:= FNascimento;
end;

procedure TCliente.SetAtivo(val: IInfraString);
begin
FAtivo := val;
end;

procedure TCliente.SetCidade(val: IInfraInteger);
begin
FCidade := val;
end;

procedure TCliente.SetDataNascimento(val : IInfraDateTime);
begin
FNascimento:=val;
end;

procedure TCliente.SetEndereco(val: IInfraString);
begin
FEndereco := val;
end;

function TCliente.GetNomeMae: IInfraString;
begin
Result:=FNomeMae;
end;

procedure TCliente.SetNomeMae(val : IInfraString);
begin
FNomeMae:=val;
end;

function TCliente.GetTelefone: IInfraString;
begin
result:= FTelefone;
end;

procedure TCliente.SetTelefone(val : IInfraString);
begin
FTelefone:=val;
end;

function TCliente.GetNome: IInfraString;
begin
Result := FNome;
end;

procedure TCliente.SetNome(val : IInfraString);
begin
FNome := val;
end;



function RegisterAccountOnReflection: IClassInfo;
begin
with TypeService do
begin
with AddType(ICliente, 'Cliente', TCliente, IInfraObject, GetType
(IInfraObject)) do
begin
AddConstructorInfo('Create', nil, @TCliente.Create);
AddPropertyInfo('Id', GetType
(IInfraInteger),@TCliente.GetID,@TCliente.SetID);
AddPropertyInfo('Nome', GetType
(IInfraString),@TCliente.GetNome,@TCliente.SetNome);
AddPropertyInfo('NomeMae', GetType
(IInfraString),@TCliente.GetNomeMae,@TCliente.SetNomeMae);
AddPropertyInfo('DataNascimento', GetType
(IInfraString),@TCliente.GetDataNascimento,@TCliente.SetDataNascimento);
AddPropertyInfo('Telefone', GetType
(IInfraDouble),@TCliente.GetTelefone,@TCliente.SetTelefone);
AddPropertyInfo('Endereco', GetType
(IInfraDouble),@TCliente.GetEndereco,@TCliente.SetEndereco);
AddPropertyInfo('Ativo', GetType
(IInfraDouble),@TCliente.GetAtivo,@TCliente.SetAtivo);
AddPropertyInfo('Cidade', GetType
(IInfraDouble),@TCliente.GetCidade,@TCliente.SetCidade);
end;
end;
end;


initialization
RegisterAccountOnReflection;
end.

[/quote]

José Henrique

unread,
Mar 27, 2009, 2:28:05 PM3/27/09
to Infra - Integrated Frameworks
Agora a interface de cidade por favor, sei que nao esta 100% pois nao
fiz o relacionamento entre as classes, se puderem me ajudar com isso.

[quote]

unit u_CidadeModelIntf;

interface

uses
InfraValueTypeIntf;

type

ICidade = interface (IInfraObject)
['{EC07BA64-1FCC-429B-81F9-5567FF444335}']
function GetID : IInfraInteger;
procedure SetID(val : IInfraInteger);
function GetNome : IInfraString;
procedure SetNome(val : IInfraString);
function GetEstado : IInfraString;
procedure SetEstado(val : IInfraString);
property ID : IInfraInteger read GetID write SetID;
property Nome : IInfraString read GetNome write SetNome;
property Estado : IInfraString read GetEstado write SetEstado;
end;



implementation

end.


[/quote]

José Henrique

unread,
Mar 27, 2009, 2:29:47 PM3/27/09
to Infra - Integrated Frameworks
Agora o model de cidade, mais uma vez aviso: Eu nao fiz o
relacionamento entre as classes se puderem me ajudar com essa parte.
vlw!

[quote]

unit u_CidadeModel;

interface

uses
InfraValueTypeIntf,
InfraValueType,
InfraCommonIntf,
u_CidadeModelIntf;


Type

TCidade = class(TInfraObject, ICidade)
private
FID:IInfraInteger;
FNome:IInfraString;
FEstado:IInfraString;
protected
function GetID : IInfraInteger;
procedure SetID(val : IInfraInteger);
function GetNome : IInfraString;
procedure SetNome(val : IInfraString);
function GetEstado : IInfraString;
procedure SetEstado(val : IInfraString);
property ID : IInfraInteger read GetID write SetID;
property Nome : IInfraString read GetNome write SetNome;
property Estado : IInfraString read GetEstado write SetEstado;
public
procedure InfraInitInstance;override;
end;




implementation

{ TCidade }

function TCidade.GetEstado: IInfraString;
begin
Result:= FEstado;
end;

function TCidade.GetID: IInfraInteger;
begin
result:= FID;
end;

function TCidade.GetNome: IInfraString;
begin
result:= FNome;
end;

procedure TCidade.InfraInitInstance;
begin
inherited;
FID := AddProperty('ID') as IInfraInteger;
FNome := AddProperty('Nome') as IInfraString;
FEstado := AddProperty('Estado') as IInfraString;
end;

procedure TCidade.SetEstado(val: IInfraString);
begin
FEstado := val;
end;

procedure TCidade.SetID(val: IInfraInteger);
begin
FID := val;
end;

procedure TCidade.SetNome(val: IInfraString);
begin
FNome := val;
end;


function RegisterAccountOnReflection: IClassInfo;
begin
with TypeService do
begin
with AddType(ICidade, 'Cidade', TCidade, IInfraObject, GetType
(IInfraObject)) do
begin
AddConstructorInfo('Create', nil, @TCidade.Create);
AddPropertyInfo('Id', GetType
(IInfraInteger),@TCidade.GetID,@TCidade.SetID);
AddPropertyInfo('Nome', GetType
(IInfraString),@TCidade.GetNome,@TCidade.SetNome);
AddPropertyInfo('Estado', GetType
(IInfraString),@TCidade.GetEstado,@TCidade.SetEstado);

Diogo Augusto Pereira

unread,
Mar 27, 2009, 2:49:39 PM3/27/09
to infra...@googlegroups.com
Esse caso já existe no demo do GUIBuilder, a única diferença é que os nomes das classes estão em inglês.

Pode ver como está implementado o relacionamento lá (classes TPerson e TCity).

Diogo


-----Mensagem original-----
De: infra...@googlegroups.com [mailto:infra...@googlegroups.com] Em nome de José Henrique
Enviada em: sexta-feira, 27 de março de 2009 15:30
Para: Infra - Integrated Frameworks
Assunto: [Infra 634] Re: Exemplo Infra

Marcos Barreto

unread,
Mar 27, 2009, 11:16:22 PM3/27/09
to infra...@googlegroups.com
Algumas considerações

1) sempre que puser um parâmetro do tipo interface ou string use o modificado const
2) E nunca esqueça de gerar guids com o CTRL+SHIFT+G, nunca copie GUID de outras interfaces .

 ICliente = interface (IInfraObject)
   ['{FA3F5E23-435E-44FA-A54C-CFCEC5D4B189}']
   function GetID : IInfraInteger;
   procedure SetID(const val : IInfraInteger);
   function GetNome : IInfraString;
   procedure SetNome(const val : IInfraString);

3) Datanascimento : IInfraDateTime; seria melhor definir o tipo IInfraDate. é mais adequado a este caso
4) Remova atributos que nao foram definidos lá em cima para simplificar, por que botar a mãe do cliente na parada? sacanagem!
5) O atributo Cidade deveria ser do tipo ICidade e nao IInfraInteger, isso é um erro muito comum entre nós programadores delphi, sempre queremos definir classes como se estivesse definindo banco de dados. é um erro. No mundo OO o Cliente faz referência a um objeto cidade e nao ao código da cidade.
6) Ativo deveria ser um IInfraBoolean e nao uma string.

Marcos Barreto

unread,
Mar 27, 2009, 11:23:14 PM3/27/09
to infra...@googlegroups.com
Algumas considerações relativas à classe Cliente:

1) fazer os acertos relativos ao que eu falei sobre a interface do mesmo.
2) Seria melhor renomear RegisterAccountOnReflection para RegisterClienteOnReflection
3) Você definiu as propriedades de Cliente para um tipo e registrou na reflexão com outros tipos, isso vai dar caruara! ex:
    DataNascimento registrou como InfraString
    Telefone registrou como InfraDouble
    Endereco registrou como InfraDouble
    Ativo registrou como InfraDouble
    Cidade registrou como InfraDouble
4) Este trabalho de criação da classe da interface e do registro na reflexão é um trabalho meio chato e que será completamente automatizado mais tarde. vc escreverá apenas a interface e um wizard na IDE já geraria a unit da classe e o registro na reflexão.

Marcos Barreto

unread,
Mar 27, 2009, 11:31:55 PM3/27/09
to infra...@googlegroups.com
A interface de cidade parece correta, suas interfaces poderiam ficar todas em uma mesma unit e as classes em outra, afinal de contas estamos falando em um exemplo simples aqui e nao em um modelo com dezenas de classes.

Agora o model de cidade, mais uma vez aviso: Eu nao fiz o
relacionamento entre as classes se puderem me ajudar com essa parte.

1) Nao existe este lançe de definir relacionamento entre as classes, pelo menos ainda nao é necessário para nada. a única coisa que tem de fazer é por em cliente o atributo cidade como ICidade em vez de InfraInteger
2) novamente o registro da cidade na reflexão está com o nome RegisterAccountOnReflection. pode renomear.

Fora estas considerações perfeito, está no caminho.

Uma coisa importante sobre o Infra

Existe uma unit chamada ApplicationContext, ao criar um novo projeto que vai usar o Infra vc deve abrir o fonte de seu arquivo .dpr e por esta unit como a primeira unit (ou a segunda se estiver usando algum gerenciador de memória como FastMM4 ou ShareMemRep).

Esta unit é responsável por dar acesso aos servicos do Infra, a falta dela pode causar problemas durante a inicialização do programa

Um abraço e parabéns Henrique. faça as mudanças sugeridas, compile e se estiver tudo ok nos avise para dar-nos continuidade, caso tenha algum problema é só informar aqui.

gmail

unread,
Mar 27, 2009, 10:57:48 PM3/27/09
to infra...@googlegroups.com
 
 
CREATE DATABASE 'C:\infra\base\DBINFRADEMOSTRACAO.GDB'
USER 'SYSDBA' PASSWORD 'masterkey'
PAGE_SIZE = 1024
DEFAULT CHARACTER SET WIN1252
 
 
 
/* Table: TBCLIENTE */
 
CREATE TABLE TBCLIENTE (
    ID INTEGER NOT NULL,
    NOME VARCHAR (50) CHARACTER SET WIN1252 COLLATE WIN1252,
    DATANASCIMENTO DATE,
    TELEFONE VARCHAR (13) CHARACTER SET WIN1252 COLLATE WIN1252,
    ENDERECO VARCHAR (50) CHARACTER SET WIN1252 COLLATE WIN1252,
    CIDADE INTEGER,
    ATIVO SMALLINT);
 
 
 
/* Primary keys definition */
 
ALTER TABLE TBCLIENTE ADD CONSTRAINT PK_TBCLIENTE PRIMARY KEY (ID);
 

/* Foreign keys definition */
 
ALTER TABLE TBCLIENTE ADD CONSTRAINT FK_TBCLIENTECIDADE FOREIGN KEY (CIDADE) REFERENCES TBCIDADE (ID) ON DELETE SET DEFAULT ON UPDATE CASCADE;
 

/* Indices definition */
 
CREATE INDEX FK_TBCLIENTECIDADE ON TBCLIENTE (CIDADE);
CREATE UNIQUE INDEX PK_TBCLIENTE ON TBCLIENTE (ID);
 
 
 
/* Table: TBCIDADE */
 
CREATE TABLE TBCIDADE (
    ID INTEGER NOT NULL,
    NOME VARCHAR (30) CHARACTER SET WIN1252 NOT NULL COLLATE WIN1252,
    ESTADO VARCHAR (2) CHARACTER SET WIN1252 NOT NULL COLLATE WIN1252);
 
 
 
/* Primary keys definition */
 
ALTER TABLE TBCIDADE ADD CONSTRAINT PK_TBCIDADE PRIMARY KEY (ID);
 

/* Indices definition */
 
CREATE UNIQUE INDEX PK_TBCIDADE ON TBCIDADE (ID);
 
Não é minha especialidade, aceito sugestoes....
 
Fernando Lopes

Marcos Barreto

unread,
Mar 28, 2009, 12:42:12 AM3/28/09
to infra...@googlegroups.com
Tá ótimo fernando. agora é montar uma telinha simples sem código. praticamente só com alguns controles para exibir um cliente e a cidade dele, nao precisa de botão para inluir nem nada assim. é só montar o form mesmo por enquanto. vamos.

gmail

unread,
Mar 27, 2009, 11:44:54 PM3/27/09
to infra...@googlegroups.com
Com controles de DBEdit ou Edit ???
----- Original Message -----

Marcos Barreto

unread,
Mar 28, 2009, 12:46:35 AM3/28/09
to infra...@googlegroups.com
controles dbedit? joga isso fora :D
Tudo controle nao dataware!

José Henrique

unread,
Mar 30, 2009, 8:41:19 AM3/30/09
to Infra - Integrated Frameworks
Fiz as modificações que falou e juntei as duas interfaces numa mesma
unit.



unit u_modelInterfaces;

interface

uses
InfraValueTypeIntf;

type

ICidade = interface (IInfraObject)
['{EC07BA64-1FCC-429B-81F9-5567FF444335}']
function GetID : IInfraInteger;
function GetNome : IInfraString;
function GetEstado : IInfraString;
procedure SetID(const val : IInfraInteger);
procedure SetNome(const val : IInfraString);
procedure SetEstado(const val : IInfraString);
{property}
property ID : IInfraInteger read GetID write SetID;
property Nome : IInfraString read GetNome write
SetNome;
property Estado : IInfraString read GetEstado write
SetEstado;
end;

ICliente = interface (IInfraObject)
['{FA3F5E23-435E-44FA-A54C-CFCEC5D4B189}']
function GetID : IInfraInteger;
function GetNome : IInfraString;
function GetDatanascimento : IInfraDate;
function GetTelefone : IInfraString;
function GetAtivo : IInfraBoolean;
function GetEndereco : IInfraString;
function GetCidade : ICidade;

procedure SetID(const val : IInfraInteger);
procedure SetNome(const val : IInfraString);
procedure SetDatanascimento(const val : IInfraDate);
procedure SetTelefone(const val : IInfraString);
procedure SetAtivo(const val : IInfraBoolean);
procedure SetEndereco(const val : IInfraString);
procedure SetCidade(const val : ICidade);

property ID : IInfraInteger read GetID write SetID;
property Nome : IInfraString read GetNome write
SetNome;
property Datanascimento : IInfraDate read
GetDatanascimento write SetDatanascimento;
property Telefone : IInfraString read GetTelefone
write SetTelefone;
property Cidade : ICidade read GetCidade write
SetCidade;
property Ativo : IInfraBoolean read GetAtivo write
SetAtivo;
property Endereco : IInfraString read GetEndereco
write SetEndereco;
end;



implementation



end.

José Henrique

unread,
Mar 30, 2009, 8:44:02 AM3/30/09
to Infra - Integrated Frameworks
Ah!! e tirei a mãe do cara da jogada, dessa vez deixo
passar ....rsrsrsrs.
Uma coisa que achei estranho como o Infra vai saber como relacionar
cliente e cidade se ele nao tem os campos de relacionamentos
explicitamente ?



unit u_ClienteModel;

interface

uses
InfraValueTypeIntf,
InfraValueType,
InfraCommonIntf,
u_ModelInterfaces;

type
TCliente = class(TInfraObject, ICliente)
private
FID:IInfraInteger;
FNome:IInfraString;
FNascimento:IInfraDate;
FTelefone:IInfraString;
FEndereco:IInfraString;
FAtivo:IInfraBoolean;
FCidade:ICidade;
protected
function GetID : IInfraInteger;
procedure SetID(const val : IInfraInteger);
function GetDataNascimento : IInfraDate;
procedure SetDataNascimento(const val : IInfraDate);
function GetTelefone : IInfraString;
procedure SetTelefone(const val : IInfraString);
function GetNome : IInfraString;
procedure SetNome(const val : IInfraString);
function GetEndereco : IInfraString;
procedure SetEndereco(const val : IInfraString);
function GetAtivo : IInfraBoolean;
procedure SetAtivo(const val : IInfraBoolean);
function GetCidade : ICidade;
procedure SetCidade(const val : ICidade);
{property's }
property ID : IInfraInteger read GetID write SetID;
property Nome : IInfraString read GetNome write
SetNome;
property Datanascimento : IInfraDate read
GetDatanascimento write SetDatanascimento;
property Telefone : IInfraString read GetTelefone
write SetTelefone;
property Cidade : ICidade read GetCidade write
SetCidade;
property Ativo : IInfraBoolean read GetAtivo write
SetAtivo;
property Endereco : IInfraString read GetEndereco
write SetEndereco;
public
procedure InfraInitInstance;override;
end;


function RegisterClienteOnReflection: IClassInfo;

implementation

procedure TCliente.InfraInitInstance;
begin
inherited;
FID := AddProperty('ID') as IInfraInteger;
FNascimento := AddProperty('Nascimento') as IInfraDate;
FNome := AddProperty('Nome') as IInfraString;
FTelefone := AddProperty('Telefone') as IInfraString;
FCidade := AddProperty('Cidade') as ICidade;
FAtivo := AddProperty('Ativo') as IInfraBoolean;
FEndereco := AddProperty('Endereco') as IInfraString;
end;

function TCliente.GetEndereco: IInfraString;
begin
Result:= FEndereco;
end;

function TCliente.GetID: IInfraInteger;
begin
Result:=FID;
end;

procedure TCliente.SetID(const val : IInfraInteger);
begin
Fid := val;
end;

function TCliente.GetAtivo: IInfraBoolean;
begin
Result:=FAtivo;
end;

function TCliente.GetCidade: ICidade;
begin
Result := FCidade;
end;

function TCliente.GetDataNascimento: IInfraDate;
begin
Result:= FNascimento;
end;

procedure TCliente.SetAtivo(const val: IInfraBoolean);
begin
FAtivo := val;
end;

procedure TCliente.SetCidade(const val: ICidade);
begin
FCidade := val;
end;

procedure TCliente.SetDataNascimento(const val :
IInfraDate);
begin
FNascimento:=val;
end;

procedure TCliente.SetEndereco(const val: IInfraString);
begin
FEndereco := val;
end;


function TCliente.GetTelefone: IInfraString;
begin
result:= FTelefone;
end;

procedure TCliente.SetTelefone(const val : IInfraString);
begin
FTelefone:=val;
end;

function TCliente.GetNome: IInfraString;
begin
Result := FNome;
end;

procedure TCliente.SetNome(const val : IInfraString);
begin
FNome := val;
end;


function RegisterClienteOnReflection: IClassInfo;
begin
with TypeService do
begin
with AddType(ICliente, 'Cliente', TCliente,
IInfraObject, GetType(IInfraObject)) do
begin
AddConstructorInfo('Create', nil, @TCliente.Create);
AddPropertyInfo('Id', GetType
(IInfraInteger),@TCliente.GetID,@TCliente.SetID);
AddPropertyInfo('Nome', GetType
(IInfraString),@TCliente.GetNome,@TCliente.SetNome);
AddPropertyInfo('DataNascimento', GetType
(IInfraDate),@TCliente.GetDataNascimento,@TCliente.SetDataNascimento);
AddPropertyInfo('Telefone', GetType
(IInfraString),@TCliente.GetTelefone,@TCliente.SetTelefone);
AddPropertyInfo('Endereco', GetType
(IInfraString),@TCliente.GetEndereco,@TCliente.SetEndereco);
AddPropertyInfo('Ativo', GetType
(IInfraBoolean),@TCliente.GetAtivo,@TCliente.SetAtivo);
AddPropertyInfo('Cidade', GetType
(ICidade),@TCliente.GetCidade,@TCliente.SetCidade);
end;
end;
end;

initialization
RegisterClienteOnReflection;
end.

José Henrique

unread,
Mar 30, 2009, 8:45:04 AM3/30/09
to Infra - Integrated Frameworks
A Unit cidade, poucas alterações foram feitas, mas foram feitas!



unit u_CidadeModel;

interface

uses
InfraValueTypeIntf,
InfraValueType,
InfraCommonIntf,
u_CidadeModelIntf;

Type

TCidade = class(TInfraObject, ICidade)
private
FID:IInfraInteger;
FNome:IInfraString;
FEstado:IInfraString;
protected
function GetID : IInfraInteger;
function GetNome : IInfraString;
function GetEstado : IInfraString;
procedure SetID(const val : IInfraInteger);
procedure SetNome(const val : IInfraString);
procedure SetEstado(const val : IInfraString);
{property }
property ID : IInfraInteger read GetID write SetID;
property Nome : IInfraString read GetNome write
SetNome;
property Estado : IInfraString read GetEstado write
SetEstado;
public
procedure InfraInitInstance;override;
end;

function RegisterCidadeOnReflection: IClassInfo;


implementation

{ TCidade }

function TCidade.GetEstado: IInfraString;
begin
Result:= FEstado;
end;

function TCidade.GetID: IInfraInteger;
begin
result:= FID;
end;

function TCidade.GetNome: IInfraString;
begin
result:= FNome;
end;

procedure TCidade.InfraInitInstance;
begin
inherited;
FID := AddProperty('ID') as IInfraInteger;
FNome := AddProperty('Nome') as IInfraString;
FEstado := AddProperty('Estado') as IInfraString;
end;

procedure TCidade.SetEstado(const val: IInfraString);
begin
FEstado := val;
end;

procedure TCidade.SetID(const val: IInfraInteger);
begin
FID := val;
end;

procedure TCidade.SetNome(const val: IInfraString);
begin
FNome := val;
end;


function RegisterCidadeOnReflection: IClassInfo;
begin
with TypeService do
begin
with AddType(ICidade, 'Cidade', TCidade, IInfraObject,
GetType(IInfraObject)) do
begin
AddConstructorInfo('Create', nil, @TCidade.Create);
AddPropertyInfo('Id', GetType
(IInfraInteger),@TCidade.GetID,@TCidade.SetID);
AddPropertyInfo('Nome', GetType
(IInfraString),@TCidade.GetNome,@TCidade.SetNome);
AddPropertyInfo('Estado', GetType
(IInfraString),@TCidade.GetEstado,@TCidade.SetEstado);
end;
end;
end;


initialization
RegisterCidadeOnReflection;
end.

José Henrique

unread,
Mar 30, 2009, 8:48:52 AM3/30/09
to Infra - Integrated Frameworks
Resumindo então, o modelo ficou com 3 units:

u_modelInterfaces; : Possui as interfaces de cliente e de cidade;

u_ClienteModel : possui a classe Cliente com seus métodos de
inicialização e registro na reflection

u_CidadeModel : possui a classe Cidade com seus métodos de
inicialização e registro na reflection

José Henrique

unread,
Mar 30, 2009, 9:10:15 AM3/30/09
to Infra - Integrated Frameworks
Errata da unit u_CidadeModel;
estava fazendo uses a unit que foi removida, por favor corrijam

unit u_CidadeModel;

interface

uses
InfraValueTypeIntf,
InfraValueType,
InfraCommonIntf,
---->> u_CidadeModelIntf;


Unit u_CidadeModel;

interface

uses
InfraValueTypeIntf,
InfraValueType,
InfraCommonIntf,
---->> u_modelInterfaces;

Marcos Barreto

unread,
Mar 30, 2009, 11:06:11 AM3/30/09
to infra...@googlegroups.com
Beleza pessoal, recebi as units aqui o script tambem vou juntar tudo e colocar no grupo.

Henrique, vc falou mais acima que nao sabia como o infra sabia sobre o relacionamento entre pessoa e cidade. bem podemos registrar isso na reflexão (apesar de nao ser necessário para este exemplo).

Se vc percebeu, existe um atributo do tipo ICidade em IPessoa, logo vc já está ligando uma classe a outra de alguma forma

José Henrique

unread,
Mar 31, 2009, 9:06:41 AM3/31/09
to Infra - Integrated Frameworks
Senhores, eu fiz um modelo de form o mais básico possível. Espero que
esse modelo sirva para concluirmos o exemplo de persistência. Não
adicionei nenhuma funcionalidade ao form.

código da unit do form e logo noutro post vou colocar o código do dfm.


unit u_Principal;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics,
Controls, Forms,
Dialogs, ComCtrls, StdCtrls, ExtCtrls, Buttons;

type
TForm1 = class(TForm)
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Edit4: TEdit;
ComboBox1: TComboBox;
CheckBox1: TCheckBox;
DateTimePicker1: TDateTimePicker;
Bevel1: TBevel;
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
BitBtn3: TBitBtn;
BitBtn4: TBitBtn;
Label7: TLabel;
Label8: TLabel;
Label9: TLabel;
Edit5: TEdit;
Edit6: TEdit;
Edit7: TEdit;
Bevel2: TBevel;
BitBtn6: TBitBtn;
BitBtn7: TBitBtn;
BitBtn8: TBitBtn;
BitBtn9: TBitBtn;
BitBtn10: TBitBtn;
Label10: TLabel;
Label11: TLabel;
procedure BitBtn10Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.BitBtn10Click(Sender: TObject);
begin
close;
end;

end.

José Henrique

unread,
Mar 31, 2009, 9:11:57 AM3/31/09
to Infra - Integrated Frameworks
Senhores segue aqui o código do DFM para criar o form do exemplo, para
aqueles que não estão familiarizados, criem um novo form e com o botão
da direita no form selecione a opção "view as text" o arquivo texto
que irá aparecer é na realidade o "script" que a IDE do Delphi
utiliza para desenhar o seu form. apague tudo e copie o código abaixo.
Depois com o botão da direita novamente selecione "view as form" ou
então tecle Alt+F12.
Espero ter ajudado.
Abs!!



object Form1: TForm1
Left = 0
Top = 0
Caption = 'Cadastro Cliente Infra'
ClientHeight = 419
ClientWidth = 556
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
object Bevel2: TBevel
Left = 8
Top = 233
Width = 524
Height = 147
end
object Bevel1: TBevel
Left = 8
Top = 10
Width = 537
Height = 185
end
object Label1: TLabel
Left = 24
Top = 38
Width = 33
Height = 13
Caption = 'C'#243'digo'
end
object Label2: TLabel
Left = 170
Top = 38
Width = 27
Height = 13
Caption = 'Nome'
end
object Label3: TLabel
Left = 24
Top = 134
Width = 45
Height = 13
Caption = 'Endereco'
end
object Label4: TLabel
Left = 172
Top = 83
Width = 42
Height = 13
Caption = 'Telefone'
end
object Label5: TLabel
Left = 26
Top = 83
Width = 55
Height = 13
Caption = 'Nascimento'
end
object Label6: TLabel
Left = 392
Top = 134
Width = 33
Height = 13
Caption = 'Cidade'
end
object Label7: TLabel
Left = 24
Top = 297
Width = 33
Height = 13
Caption = 'C'#243'digo'
end
object Label8: TLabel
Left = 24
Top = 329
Width = 27
Height = 13
Caption = 'Nome'
end
object Label9: TLabel
Left = 24
Top = 353
Width = 33
Height = 13
Caption = 'Estado'
end
object Label10: TLabel
Left = 24
Top = 16
Width = 134
Height = 16
Caption = 'Cadastro de Clientes'
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -13
Font.Name = 'Tahoma'
Font.Style = [fsBold]
ParentFont = False
end
object Label11: TLabel
Left = 24
Top = 256
Width = 133
Height = 16
Caption = 'Cadastro de Cidades'
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -13
Font.Name = 'Tahoma'
Font.Style = [fsBold]
ParentFont = False
end
object Edit1: TEdit
Left = 24
Top = 56
Width = 121
Height = 21
TabOrder = 0
Text = 'Edit1'
end
object Edit2: TEdit
Left = 170
Top = 56
Width = 362
Height = 21
TabOrder = 1
Text = 'Edit2'
end
object Edit3: TEdit
Left = 24
Top = 153
Width = 362
Height = 21
TabOrder = 2
Text = 'Edit3'
end
object Edit4: TEdit
Left = 170
Top = 102
Width = 121
Height = 21
TabOrder = 3
Text = 'Edit4'
end
object ComboBox1: TComboBox
Left = 392
Top = 153
Width = 145
Height = 21
ItemHeight = 13
TabOrder = 4
Text = 'ComboBox1'
end
object CheckBox1: TCheckBox
Left = 24
Top = 176
Width = 97
Height = 17
Caption = 'Cadastro Ativo'
TabOrder = 5
end
object DateTimePicker1: TDateTimePicker
Left = 26
Top = 102
Width = 119
Height = 21
Date = 39903.407390219910000000
Time = 39903.407390219910000000
TabOrder = 6
end
object BitBtn1: TBitBtn
Left = 8
Top = 199
Width = 75
Height = 25
Caption = 'Carregar'
TabOrder = 7
end
object BitBtn2: TBitBtn
Left = 251
Top = 199
Width = 75
Height = 25
Caption = 'Salvar'
TabOrder = 8
end
object BitBtn3: TBitBtn
Left = 89
Top = 199
Width = 75
Height = 25
Caption = 'Incluir'
TabOrder = 9
end
object BitBtn4: TBitBtn
Left = 170
Top = 199
Width = 75
Height = 25
Caption = 'Excluir'
TabOrder = 10
end
object Edit5: TEdit
Left = 63
Top = 294
Width = 121
Height = 21
TabOrder = 11
Text = 'Edit5'
end
object Edit6: TEdit
Left = 63
Top = 323
Width = 121
Height = 21
TabOrder = 12
Text = 'Edit6'
end
object Edit7: TEdit
Left = 63
Top = 350
Width = 121
Height = 21
TabOrder = 13
Text = 'Edit7'
end
object BitBtn6: TBitBtn
Left = 8
Top = 386
Width = 75
Height = 25
Caption = 'Carregar'
TabOrder = 14
end
object BitBtn7: TBitBtn
Left = 89
Top = 386
Width = 75
Height = 25
Caption = 'Incluir'
TabOrder = 15
end
object BitBtn8: TBitBtn
Left = 170
Top = 386
Width = 75
Height = 25
Caption = 'Excluir'
TabOrder = 16
end
object BitBtn9: TBitBtn
Left = 251
Top = 386
Width = 75
Height = 25
Caption = 'Salvar'
TabOrder = 17
end
object BitBtn10: TBitBtn
Left = 470
Top = 386
Width = 75
Height = 25
Caption = 'Sair'
TabOrder = 18
OnClick = BitBtn10Click
end
end
Reply all
Reply to author
Forward
0 new messages