Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Trucos (https://www.clubdelphi.com/foros/forumdisplay.php?f=52)
-   -   Componente con una propiedad tipo lista desplegable (https://www.clubdelphi.com/foros/showthread.php?t=80531)

Julián 30-06-2006 00:34:23

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.


La franja horaria es GMT +2. Ahora son las 13:06:38.

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