Ver Mensaje Individual
  #1  
Antiguo 30-06-2006
Avatar de Julián
Julián Julián is offline
Merodeador
 
Registrado: may 2003
Ubicación: en mi casa
Posts: 2.019
Reputación: 10
Julián Va por buen camino
Componente con una propiedad tipo lista desplegable

Este ejmplo sirve para hacer una componente con una propiedad que sea una lista desplegable como por ejemplo la propiedad DatBaseNames o la propiedad TableName del TTable

Código Delphi [-]
unit ComponenteConLista;

uses
  ....., DsgnIntf, ......;
  // deberias añadir el path de DsgnIntf
  // al Library Path, en ese .pas es en
  // donde se define TStringProperty
  // DsgnIntf está en
  // $(DELPHI)\source\ToolsApitype

  TPropiedadLista = class (TStringProperty)
  public
    function GetAttributes : TPropertyAttributes; override;
    procedure GetValues(Proc : TGetStrProc); override;
  end;

  TComponenteConLista = class(TComponent)
  private
    { Private declarations }
    FLista: string;
  protected
    { Protected declarations }
  public
    constructor Create(AOwner : TComponent); override;
    { Public declarations }
  published
    { Published declarations }
    property Lista: string read FLista write FLista;
  end;

procedure Register;

implementation

procedure Register;
begin
  RegisterComponents('ClubDelphi', [TComponenteConLista]);
  RegisterPropertyEditor(TypeInfo(String),TComponenteConLista,'Lista',TPropiedadLista);
end;

constructor TComponenteConLista.Create(AOwner: TComponent);
begin
  inherited;
end;

{ TPropiedadLista }
function TPropiedadLista.GetAttributes: TPropertyAttributes;
begin
  Result:=[paValueList, paSortList];
end;

procedure TPropiedadLista.GetValues(Proc: TGetStrProc);
var
  ListaDeCosas : TStrings;
  i : integer;
begin
  ListaDeCosas := TStringList.Create;
  try
    ListaDeCosas.Add('UnaCosa');
    ListaDeCosas.Add('OtraCosa');
    ListaDeCosas.Add('OtraMas');
    // Podrias usar SessionGetTableNames para, por ejemplo, obtener
    // los nombres de las tablas de un alias
    for i:=0 to ListaDeCosas.Count - 1 do Proc(ListadeCosas[i]);
  finally
    ListaDeCosas.Free;
  end;
end;

end.
Responder Con Cita