Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Principal > OOP
Registrarse FAQ Miembros Calendario Guía de estilo Temas de Hoy

Grupo de Teaming del ClubDelphi

 
 
Herramientas Buscar en Tema Desplegado
  #5  
Antiguo 31-10-2007
Avatar de ariefez
ariefez ariefez is offline
Miembro
 
Registrado: sep 2005
Ubicación: Perú - Lima
Posts: 63
Poder: 19
ariefez Va por buen camino
Guiate de esta unidad tiene lo basico pa crear las colecciones

Código Delphi [-]
unit Prueba;

interface

uses
  Classes;

type

  { TMiItem }

  TMiComponente = class;

  TMiItem = class(TCollectionItem)
  private
    FAlignment: TAlignment;
  protected
    function  GetMiComponente: TMiComponente;
    function GetDisplayName: string; override;
  public
    procedure Assign(Source: TPersistent); override;
    property  MiComponente: TMiComponente read GetMiComponente;
  published
    property Alignment: TAlignment read FAlignment write FAlignment default taLeftJustify;
  end;

  { TMiLista }

  TMiItemClass = class of TMiItem;

  TMiLista = class(TCollection)
  private
    FMiComponente: TMiComponente;
    function GetMiItem(Index: Integer): TMiItem;
    procedure SetMiItem(Index: Integer; Value: TMiItem);
  protected
    function GetOwner: TPersistent; override;
    procedure Update(Item: TCollectionItem); override;
  public
    constructor Create(MiComponente: TMiComponente;
      InfoListClass: TMiItemClass);
    function Add: TMiItem;
    property MiComponente: TMiComponente read FMiComponente;
    property Items[Index: Integer]: TMiItem read GetMiItem write SetMiItem; default;
  end;

  TMiComponente = class(TComponent)
  private
    FMiLista: TMiLista;
    procedure SetMiLista(const Value: TMiLista);
  protected
    function CreateMiLista: TMiLista; dynamic;
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
  published
    property MiLista: TMiLista read FMiLista write SetMiLista;
  end;

procedure Register;

implementation

procedure Register;
begin
  RegisterComponents('Ejemplos', [TMiComponente]);
end;

{ TMiComponente }

constructor TMiComponente.Create(AOwner: TComponent);
begin
  inherited;

  FMiLista := CreateMiLista;
end;

function TMiComponente.CreateMiLista: TMiLista;
begin
  Result := TMiLista.Create(Self, TMiItem);
end;

destructor TMiComponente.Destroy;
begin
  FMiLista.Free;

  inherited;
end;

procedure TMiComponente.SetMiLista(const Value: TMiLista);
begin
  FMiLista := Value;
end;

{ TMiItem }

procedure TMiItem.Assign(Source: TPersistent);
begin
  if Source is TMiItem then
  begin
    if Assigned(Collection) then
      Collection.BeginUpdate;
    try
      FAlignment := TMiItem(Source).Alignment;
    finally
      if Assigned(Collection) then
        Collection.EndUpdate;
    end;
  end else
    inherited Assign(Source);
end;

function TMiItem.GetDisplayName: string;
begin
//  Result := 'Nombre q quieras ver en el inspector';
//  if Result = '' then
    Result := inherited GetDisplayName;
end;

function TMiItem.GetMiComponente: TMiComponente;
begin
  if Assigned(Collection) and (Collection is TMiLista) then
    Result := TMiLista(Collection).MiComponente
  else
    Result := nil;
end;

{ TMiLista }

function TMiLista.Add: TMiItem;
begin
  Result := TMiItem(inherited Add);
end;

constructor TMiLista.Create(MiComponente: TMiComponente;
  InfoListClass: TMiItemClass);
begin
  inherited Create(InfoListClass);
  FMiComponente := MiComponente;
end;

function TMiLista.GetMiItem(Index: Integer): TMiItem;
begin
  Result := TMiItem(inherited Items[Index]);
end;

function TMiLista.GetOwner: TPersistent;
begin
  Result := FMiComponente;
end;

procedure TMiLista.SetMiItem(Index: Integer; Value: TMiItem);
begin
  Items[Index].Assign(Value);
end;

procedure TMiLista.Update(Item: TCollectionItem);
begin
  inherited;

  // Actualizacion forma global o por item segun sea "Item"
end;

end.
Responder Con Cita
 



Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

Temas Similares
Tema Autor Foro Respuestas Último mensaje
usar un editor de propiedades para TCollectionItem droguerman OOP 2 13-05-2007 21:55:31
IIS no funciona YaninaGenia .NET 2 26-07-2006 14:21:59
BDE, no funciona martita Conexión con bases de datos 4 26-05-2006 22:21:12
¿Colecciones? jam888 Varios 2 02-01-2006 17:39:08
Descendiente de TCollectionItem de solo lectura adlfv OOP 3 15-09-2005 15:59:55


La franja horaria es GMT +2. Ahora son las 17:48:02.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi
Copyright 1996-2007 Club Delphi