AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Code-Bibliothek Neuen Beitrag zur Code-Library hinzufügen Delphi Listbox - OnMeasureItem kann nicht auf Objekt zugreifen
Thema durchsuchen
Ansicht
Themen-Optionen

Listbox - OnMeasureItem kann nicht auf Objekt zugreifen

Ein Thema von HeinzJ · begonnen am 13. Mai 2009
Antwort Antwort
HeinzJ

Registriert seit: 17. Aug 2007
Ort: Bremen
84 Beiträge
 
Delphi 2007 Architect
 
#1

Listbox - OnMeasureItem kann nicht auf Objekt zugreifen

  Alt 13. Mai 2009, 12:08
Im Ereignis OnMeasureItem kann in einer ListBox nach dem
Hinzufügen eines neuen Items (invl. Objekt, z.B. einer Bitmap)
nicht auf das Objekt zugegriffen werden.

Mir hilfreich war Peter Below (TeamB) sowie dieser Code:

Zitat:
"Yes, this [Objekt nicht verfügbar nach Add] is an old problem caused by the fact that the AddObject method internally has to send two messages to the Windows listbox control. The first creates the item and sets it text, the second stores the object into the item. Unfortunately it is the first message (LB_ADDSTRING or LB_INSERTSTRING) that causes the WM_MEASUREITEM message to be end back, so the object has not been stored yet when the OnMeasureItem event fires. The best way to fix this is to simply ignore he OnMeasureItem event. Instead you measure the item immediately after the AddObject call and send a LB_SETITEMHEIGHT message to the listbox to tell it the height. Peter Below (TeamB)
Delphi-Quellcode:
// Aufruf z.B. nach aListbox.Add
// => ListBoxRefreshItem(aListBox, aListBox.Items.Count-1);
// oder aListBox.Items.Move(oldPos, newPos);
// => ListBoxRefreshItem(aListBox, newPos);

procedure TXYZ.ListBoxRefreshItem(Control: TWinControl; index:
    integer);
var
  lb: TListBox;
  H: integer;
begin
  lb := TListBox(Control);
  if lb.Style = lbStandard then exit;
  ListBoxMeasureItem(lb, index, H); // Siehe unten
  lb.Perform (LB_SETITEMHEIGHT, index, MAKELPARAM(H, 0));
  lb.refresh;
end;
Delphi-Quellcode:
procedure THeavyLiftEditDlg.ListBoxMeasureItem(Control: TWinControl; Index:
    Integer; var Height: Integer);
var
   lb: TListbox;
   Bitmap: TBitmap;
begin
   if Index = -1 then exit;

   lb := TListBox(Control);
   Bitmap:= TBitmap( lb.Items.Objects[Index] )

   // Measure hight according to available subitem entries.
   with lb.Canvas do
   begin

      // Measure height sample
      Font.Style := [fsBold];
      Height := TextHeight('Wg') + 2 ;
      Height := Bitmap.Height;
   end;
end;
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 13:57 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz