Thema: Delphi abgeleitete ComboBox

Einzelnen Beitrag anzeigen

DelphiDeveloper

Registriert seit: 9. Apr 2003
Ort: Köln
256 Beiträge
 
Delphi XE2 Enterprise
 
#5

Re: abgeleitete ComboBox

  Alt 30. Mär 2004, 14:33
Einfach Neue Komponente von TComboBox ableiten

Delphi-Quellcode:
unit ComboBoxWithItems;

interface

uses
  Windows, Messages, SysUtils, Classes, Controls, StdCtrls;

type
  TComboBoxWithItems = class(TComboBox)
  private
    { Private-Deklarationen }
  protected
    { Protected-Deklarationen }
  public
    { Public-Deklarationen }
    procedure CreateWnd; override;
    constructor create(AOwner: TComponent); override;
  published
    { Published-Deklarationen }
  end;

procedure Register;

implementation

procedure Register;
begin
  RegisterComponents('DelphiDeveloper', [TComboBoxWithItems]);
end;

{ TComboBoxWithItems }

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

procedure TComboBoxWithItems.CreateWnd;
begin
  inherited CreateWnd;
  Items.Add('My Entry 1');
  Items.Add('MY Entry 2');
  ItemIndex := 0;
end;

end.
Beachte bitte dass die Items im Constructor noch nicht zur Verfuegung stehen,
weil dort das window handle der Komponente noch nicht bekannt ist.
das wiederum liegt daran da solange kein parent gesetzt ist, das window handle nicht zugewiesen
werden kann.
Also im create zu früh!
daher kannst du die Itemliste erst im CreateWnd befuellen.
  Mit Zitat antworten Zitat