LCL: Trying to fix issue #19882: Invalid type cast error... Now there are AVs elsewhere

git-svn-id: trunk@31890 -
This commit is contained in:
juha 2011-08-06 12:48:49 +00:00
parent 22cd2415cb
commit dd75c9b748

View File

@ -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);