Search code examples
delphilistlistviewtobject

Get position of object in a list in Delphi?


I was wondering how you get a position of a certain object in a list that is created. Lets say it is like a graphical list where you can click on objects. Lets say you right click on a object and click "Refresh", how do I get the position of that object so that after the whole list is refreshed (refreshes with a clearlist for some reason) i go back to the same position in the list? This is if the list is say 1000 objects long which makes it bothersome to try and scroll down to the same position after the refresh.

The code uses Tobject but can i do something like position:=integer(TObject."pointerinfo???"); And after that when the program refreshes like set the position of the view to the pointer like currentview(pointer) or something like that?

Actually it doesn't have to be the same object, but the same "view" of the list would be even better.

Thanks in advance


Solution

  • So I think with the help I got I answered my own question. What I did was write something that took the x and y position of the listview and later after I did the refresh with a clearlist, I used the scroll function to get back to the same function. My program looks something like this.

    procedure Refresh(Sender: TObject);
    var
      horzpos:integer;
      vertpos:integer;
    begin
        horzpos:=ListView1.ViewOrigin.X;
        vertpos:=ListView1.ViewOrigin.Y;
        RefreshListView(ListView1); //A function that refreshes the list and clears it
        ListView1.Scroll(horzpos, vertpos);
     end;
    

    Maybe I should've stated earlier that it was a listview type and that I wanted to get back to the same position again after the "clearlist".

    Thanks for all the help, this community rocks!