Einzelnen Beitrag anzeigen

Benutzerbild von Helmi
Helmi

Registriert seit: 29. Dez 2003
Ort: Erding, Republik Bayern
3.312 Beiträge
 
Delphi XE2 Professional
 
#1

zur Laufzeit erzeugte ComboBox zeigt keine Bitmaps an

  Alt 29. Apr 2007, 12:22
Hallo,

ich erzeuge zur Laufzeit eine ComboBox und weis der 2 Bitmaps als Objects zu:
Delphi-Quellcode:
procedure TForm1.FormCreate(Sender: TObject);
var
  Bitmap1, Bitmap2: TBitmap;

begin
  //Bitmaps erzeugen
  Bitmap1 := TBitmap.Create;
  Bitmap2 := TBitmap.Create;

  try
    //Bilder in Bitmaps laden
    Bitmap1.LoadFromFile('d:\Original.bmp');
    Bitmap2.LoadFromFile('d:\modified.bmp');

    //ComboBox auferzeugen und beschreiben
    ComboBox_SG := TComboBox.Create(StringGrid1);
    with ComboBox_SG do
      begin
        Parent := StringGrid1;
        Visible := false;
        Enabled := true;
        Style := csOwnerDrawVariable;

        ItemHeight := 14;

        //Bitmaps in ComboBox aufnehmen
        Items.AddObject('', Bitmap1);
        Items.AddObject('', Bitmap2);

        //Properties:
        OnChange := OnChangeComboBox_SG;
        OnDrawItem := OnDrawItemComboBox_SG;
        OnExit := OnExitComboBox_SG;
      end;

    StringGrid_aufbauen;
  finally
    FreeAndNil(Bitmap1);
    FreeAndNil(Bitmap2);
  end;
end;
Im DrawItem der ComboBox hab ich das drin:
Delphi-Quellcode:
var
  Bitmap: TBitmap;
  Offset: Integer;
begin
  offset := 0;
  with ComboBox1.Canvas do
  begin
    FillRect(Rect);
    Bitmap := TBitmap(ComboBox1.Items.Objects[Index]);
    if Bitmap <> nil then
    begin
      //copy bitmap to combobox coordinate
      BrushCopy(Bounds(Rect.Left + 2, Rect.Top + 2, Bitmap.Width,
        Bitmap.Height), Bitmap, Bounds(0, 0, Bitmap.Width,
        Bitmap.Height), clred);
      Offset := Bitmap.Width + 8;
    end;
    //Set a caption to each item
    TextOut(Rect.Left + Offset, Rect.Top, Combobox1.Items[Index]);
  end;
Ich kann es compilieren, nur werden die Bitmaps nicht angezeigt.
Wenn ich das ganze mit nicht-zur-Laufzeit-erzeugten ComboBox mache, funktioniert es.

Irgendwas überseh ich - nur was?
mfg
Helmi

>> Theorie ist Wissen, dass nicht funktioniert - Praxis ist, wenn alles funktioniert und keiner weiss warum! <<
  Mit Zitat antworten Zitat