From dd75c9b748e9b70c2dd2e380e180b737f539013a Mon Sep 17 00:00:00 2001 From: juha Date: Sat, 6 Aug 2011 12:48:49 +0000 Subject: [PATCH] LCL: Trying to fix issue #19882: Invalid type cast error... Now there are AVs elsewhere git-svn-id: trunk@31890 - --- lcl/include/customlistbox.inc | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/lcl/include/customlistbox.inc b/lcl/include/customlistbox.inc index 6293746fbc..81278bf912 100644 --- a/lcl/include/customlistbox.inc +++ b/lcl/include/customlistbox.inc @@ -107,17 +107,20 @@ end; procedure TCustomListBox.InitializeWnd; var NewStrings: TStrings; + OldItems: TStrings; // TExtendedStringList or TGtkListStoreStringList or something else i, cnt: integer; - OldItems: TExtendedStringList; begin LockSelectionChange; inherited InitializeWnd; // fetch the interface item list NewStrings := TWSCustomListBoxClass(WidgetSetClass).GetStrings(Self); // copy the items (text+objects) - OldItems := FItems as TExtendedStringList; - OldItems.Sorted := False;// make sure the items are not reordered (needed for ItemIndex and attributes) - NewStrings.Assign(Items); + OldItems := FItems; + // make sure the items are not reordered (needed for ItemIndex and attributes) + // Note: TGtkListStoreStringList and other also have "Sorted" but it does not inherit from TStrings. + if FItems is TExtendedStringList then + (OldItems as TExtendedStringList).Sorted := False; + NewStrings.Assign(FItems); // new item list is the interface item list FItems := NewStrings; @@ -129,10 +132,11 @@ begin SendItemIndex; // copy items attributes - cnt := OldItems.Count; - for i := 0 to cnt - 1 do - AssignCacheToItemData(i, OldItems.Records[i]); - + if FItems is TExtendedStringList then begin + cnt := OldItems.Count; + for i := 0 to cnt - 1 do + AssignCacheToItemData(i, (OldItems as TExtendedStringList).Records[i]); + end; // free old items OldItems.Free; TWSCustomListBoxClass(WidgetSetClass).SetSorted(Self, FItems, FSorted);