Ver Mensaje Individual
  #2  
Antiguo 03-10-2007
Avatar de xEsk
[xEsk] xEsk is offline
Miembro Premium
 
Registrado: feb 2006
Posts: 454
Reputación: 19
xEsk Va por buen camino
El problema, está en que intentas cargas los items antes de que esté "configurado del todo".

Haciéndolo así, sí que funciona (debes añadir los items en "CreateWnd"):
Código Delphi [-]
implementation

{$R *.dfm}
{$R hispania.res}

  // TCustomComboHispania
  type
    TCustomComboHispania = class(TCustomComboBox)
    private
      FProvincias : boolean;
      procedure SetProvincias(Value : boolean);
    protected
      procedure CreateWnd; override; // añade esto
    public
      constructor Create(AOwner : TComponent); override;
      property Provincias : boolean read FProvincias write SetProvincias; 
    published
      
  end;

  constructor TCustomComboHispania.create(AOwner : TComponent);
  begin
    inherited Create(AOwner);
    style := csDropDownList;
    ShowHint := True;
    Sorted := false;
  end;

  procedure TCustomComboHispania.CreateWnd;
  begin
    inherited CreateWnd;
    Provincias := True; // aqui si puedes, decirle que añada las provincias
  end;

  procedure TCustomComboHispania.SetProvincias(Value : boolean);
    var
     R : TResourceStream;
  begin
    FProvincias := Value;
    R := TResourceStream.create(hInstance, 'PROVINCIAS_ESPANNOLAS', RT_RCDATA);
    try
      items.loadFromStream(R);
    finally
      R.Free;
    end;

  end;

 /////////////////////////////////////////////////////////////////////////////

 // PROBANDO EL OBJETO ANTES DE INSTALARLO EN LA PALETA DE COMPONENTES

 var
  Combo : TCustomComboHispania;

procedure TForm1.Button1Click(Sender: TObject);
begin
  Combo := TCustomComboHispania.create(form1);
  Combo.left := 30;
  Combo.Top := 30;
  Combo.parent := self;
end;

end

Última edición por xEsk fecha: 03-10-2007 a las 02:01:44.
Responder Con Cita