Somewhere within a listview WndProc (after having finished a context menu dialog), i do a call to a CustomListview Selected.EditCaption (Lazaraus 2.0.12 Windows x64).
- That worked flawlessly with Delphi 7
- This works flawlessly if the number of listview items (for which the contect menu did appear) is so small that all items do fit within the visible area of the listview
* If the number of items if higher so that not all items do fit within the visible areas, the following does happen:
- i did select for instance the second element in the list ('abc.txt'),
- the inplace editor does not open, but the selection shifts to the last elemen in the list ('zzz.txt').
I isolated the problem within
listitem.inc as follows:
notice that i used some test variables for to show where the issue happens:
function TListItem.EditCaption: Boolean;
var
LV: TCustomListView;
xx_before1, xx_before2: String; i_before1, i_before2: Integer;
xx_after1, xx_after2: String; i_after1, i_after2: Integer;
xx_after3, xx_after4: String; i_after3, i_after4: Integer;
begin
LV := FOwner.FOwner;
xx_before1 := LV.Selected.caption; // contains 'aaa.txt', correct
xx_before2 := self.caption; // contains 'aaa.txt', correct
i_before1 := LV.ItemIndex; // contains (eg.) 2, correct
i_before2 := self.Index; // contains (eg.) 2, correct
LV.Selected := Nil; // First clear all selections,
LV.Selected := Self; // then set this item as the only selected.
xx_after1 := LV.Selected.caption; // contains 'zzz.txt', wrong (last element!)
xx_after2 := self.caption; // contains 'zzz.txt', wrong (last element!)
i_after1 := LV.ItemIndex; // contains (eg.) 52; wrong
i_after2 := self.Index; // contains (eg.) 52; wrong
// I try to fix it by another way to restore the previous selection:
LV.Selected := LV.Items[i_before1]; // ****** This is my test for to fix ******
// This does restore the previous selected / single item correctly
xx_after3 := LV.Selected.caption; // contains 'aaa.txt', correct again
xx_after4 := self.caption; // contains 'aaa.txt', correct again
i_after3 := LV.ItemIndex; // contains (eg.) 2, correct again
i_after4 := self.Index; // contains (eg.) 2, correct again
if LV.ReadOnly or (LV.FEditor=nil) then
exit(false);
LV.ShowEditor;
Result:=true;
end;
So i'm pretty sure where the issues begins, but i don't understand fully why.
I assume , the selection restore via LV.Selected := Self might use a wrong pointer now who had been influenced by "LV.Selected := nil". (But why **
only then when the number of items increases the visiible part of the listview** ?)
It seems that "Self" after the assignment " LV.Selected := Nil" is not the same as before, but is itself a victim of the operation.
Might thee somehing been missing (with regard to assure the selection) before the EditCaption began?