Ver Mensaje Individual
  #6  
Antiguo 28-09-2005
Avatar de rastafarey
rastafarey rastafarey is offline
Miembro
 
Registrado: nov 2003
Posts: 927
Reputación: 21
rastafarey Va por buen camino
Resp

Mira unejemplo.

Clase op;

clase dm

clase ops //es un listados de op

ops pose un variable d tipo op para manejar listas multiples

op tiene una variable de dm para menejo de a data

por suspuesto lo smetodos de dm son astractos y los de op tambien

entonces tienes una clase que hereda tform tendria una variable tipo ops para menejar sucontenido porsupuesto los metodos de la forma deben ser abtractos para que puedan llamar a los metodos de la clase que heredo y no de la base.

De esta manera puedes manejar tus clases de negocio independientemente ya que cada quien tendra que sobresescribir los metodos abstractos y form llamara al herdados por cada quien.

Bueno aqui tiene un codigo para un objeto persistente.

me disculpan por el codigo pero no se como poner el link a lo sarchivoa atachados.
Código Delphi [-]
unit OP;

interface

Uses Contnrs;

Type

  __TIdOP = Int64;

  __TMD = Class;

  __TOP = Class
  private
    FId: __TIdOP;
    FEsproxy: Boolean;
    procedure SetEsproxy(const Value: Boolean);
  Protected
    Md : __TMD;
  Public
    Constructor Create; Virtual;
    Procedure Leer; Virtual;
    Procedure Guardar; Virtual;
    Procedure Borrar; Virtual;
    Property Id : __TIdOP Read FId;
    Property Esproxy: Boolean read FEsproxy write SetEsproxy;
  End;

  __TMD = Class
  Protected
    Function DbLeerOP(pOP: __TOP): __TIdOP; Virtual; Abstract;
    Function DbGuardarOP(pOP: __TOP): __TIdOP; Virtual; Abstract;
    Procedure DbBorrarOP(pOP: __TOP); Virtual; Abstract;
    Function PxLeerOP(pOP: __TOP): __TIdOP; Virtual; Abstract;
    Function PxGuardarOP(pOP: __TOP): __TIdOP; Virtual; Abstract;
    Procedure PxBorrarOP(pOP: __TOP); Virtual; Abstract;
  End;

  __TOPClase = Class Of __TOP;

  __TOPS = Class(TObjectList)
  private
    FIndice : Integer;
    function GetEsUltimo: Boolean;
    function GetPrimero: Boolean;
    function GetVacio: Boolean;
  Protected
    function GetIndice(Ind: Integer): __TOP;
    procedure SetIndice(Ind: Integer; const Value: __TOP);
    function GetOP: __TOP;
    Function Nuevo(__OPClase: __TOPClase): __TOP;
    Function Existe(Const cIds: Array Of Const): Boolean; Virtual;
  Public
    Constructor Create;
    Procedure Primero;
    Procedure Ultimo;
    Procedure Anterior;
    Procedure Siguiente;
    procedure Insertar(cIndice: Integer; pOP: __TOP);

    Function Agregar(pOP: __TOP): Integer;
    function Extraer(cIndice: TObject): __TOP;
    function Remover(pOP: __TOP): Integer;
    function IndeceDe(pOP: __TOP): Integer;

    Property EsPrimero: Boolean Read GetPrimero;
    Property EsUltimo: Boolean Read GetEsUltimo;
    Property Vacio: Boolean Read GetVacio;
    Property OP: __TOP Read GetOP;
    Property Indices[Ind: Integer]: __TOP Read GetIndice Write SetIndice;
    Property Indice: Integer Read FIndice;
  End;

Const
  csIdOPNulo = -1;

implementation

uses SysUtils, Classes;

{ __TOP }

procedure __TOP.Borrar;
begin
  If FEsproxy Then
    Md.PxBorrarOP(Self)
  Else
    Md.DbBorrarOP(Self)
end;

constructor __TOP.Create;
begin
  inherited Create;
  FId := csIdOPNulo;
  FEsproxy := False;
  Md := Nil;
end;

procedure __TOP.Guardar;
begin
  If FEsproxy Then
    FId := Md.PxGuardarOP(Self)
  Else
    FId := Md.DbGuardarOP(Self)
end;

Procedure __TOP.Leer;
begin
  If FEsproxy Then
    FId := Md.PxLeerOP(Self)
  Else
    FId := Md.DbLeerOP(Self)
end;

procedure __TOP.SetEsproxy(const Value: Boolean);
begin
  FEsproxy := Value;
end;

{ __TOPS }

procedure __TOPS.Anterior;
begin
  Dec(FIndice);
end;

constructor __TOPS.Create;
begin
  inherited Create;
  FIndice := -1;
end;

function __TOPS.GetOP: __TOP;
begin
  Result := __TOP(Items[FIndice]);
end;

function __TOPS.GetEsUltimo: Boolean;
begin
  Result := FIndice >= Count;
end;

function __TOPS.GetPrimero: Boolean;
begin
  Result := FIndice < 0;
end;

procedure __TOPS.Primero;
begin
  FIndice := 0;
end;

procedure __TOPS.Siguiente;
begin
  Inc(FIndice);
end;

procedure __TOPS.Ultimo;
begin
  FIndice := Count-1;
end;

function __TOPS.Agregar(pOP: __TOP): Integer;
begin
   Result := inherited Add(pOP);
end;

function __TOPS.Extraer(cIndice: TObject): __TOP;
begin
  Result := __TOP(inherited Extract(cIndice));
end;

function __TOPS.IndeceDe(pOP: __TOP): Integer;
begin
  Result := inherited IndexOf(pOP);
end;

procedure __TOPS.Insertar(cIndice: Integer; pOP: __TOP);
begin
  inherited Insert(cIndice, pOP);
end;

function __TOPS.Remover(pOP: __TOP): Integer;
begin
  Result := inherited Remove(pOP);
end;

function __TOPS.GetIndice(Ind: Integer): __TOP;
begin
  Result := __TOP(inherited Items[Ind]);
end;

function __TOPS.GetVacio: Boolean;
begin
  Result := Count > 0;
end;

procedure __TOPS.SetIndice(Ind: Integer; const Value: __TOP);
begin
  inherited Items[Ind] := Value;
end;

function __TOPS.Existe(const cIds: array of Const): Boolean;
begin
  Result := False;
end;

function __TOPS.Nuevo(__OPClase: __TOPClase): __TOP;
begin
  Result := __OPClase.Create;
  Agregar(Result);
end;

end.
__________________
Todo se puede, que no exista la tecnología aun, es otra cosa.
Responder Con Cita