Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 730955
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T06:58:15+00:00 2026-05-14T06:58:15+00:00

I am trying to remove duplicates in my listview. This function: procedure RemoveDuplicates(const LV:TbsSkinListView);

  • 0

I am trying to remove duplicates in my listview.

This function:

procedure RemoveDuplicates(const LV:TbsSkinListView);
var 
  i,j: Integer;
begin   
  LV.Items.BeginUpdate;  
  LV.SortType := stText;   
  try
    for i := 0 to LV.Items.Count-1 do  
    begin
      for j:=i+1 to LV.Items.Count-1 do
      begin  
        if  SameText(LV.Items[i].SubItems[0], LV.Items[j].SubItems[0]) and
        SameText(LV.Items[i].SubItems[1], LV.Items[j].SubItems[1]) and
        SameText(LV.Items[i].SubItems[2], LV.Items[j].SubItems[2]) and
        SameText(LV.Items[i].SubItems[3], LV.Items[j].SubItems[3])  then     
        LV.Items.Delete(j);
      end;   
    end;   
  finally
    LV.SortType := stNone;
    LV.Items.EndUpdate;   
  end;
  ShowMessage('Deleted');    
end;

does not delete the duplicates. What is wrong with it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T06:58:16+00:00Added an answer on May 14, 2026 at 6:58 am

    At a guess, since you haven’t mentioned what is going wrong, I would think that is has to do with the fact that i and j are invalid after you have deleted an item because you are counting UP.

    A better idea would be to count down instead:

    procedure RemoveDuplicates(const LV:TbsSkinListView);
    var 
      i,j: Integer;
    begin   
      LV.Items.BeginUpdate;  
      LV.SortType := stText;   
      try
        for i := LV.Items.Count-1 downto 0 do // <- this loop now counts _down_
        begin
          for j:= LV.Items.Count-1 downto i+1 do // <- this loop now counts _down_
          begin  
            if  SameText(LV.Items[i].SubItems[0], LV.Items[j].SubItems[0]) and
                SameText(LV.Items[i].SubItems[1], LV.Items[j].SubItems[1]) and
                SameText(LV.Items[i].SubItems[2], LV.Items[j].SubItems[2]) and
                SameText(LV.Items[i].SubItems[3], LV.Items[j].SubItems[3]) then     
              LV.Items.Delete(j);
          end;   
        end;   
      finally
        LV.SortType := stNone;
        LV.Items.EndUpdate;   
      end;
      ShowMessage('Deleted');    
    end;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to remove duplicate items in a list through a dictionary: def RemoveDuplicates(list):
I have been trying to use array_unique to remove duplicates from the search results
I am trying to write a very simple method to remove duplicates in a
This will probably be an extremely simple question. I'm simply trying to remove duplicate
I'm trying to remove duplicates from a MySQL table using ALTER IGNORE TABLE +
I'm trying to create a generic function that removes duplicates from an std::vector. Since
I have 6 list items $('.favorite-tag-group li').each(function(){ console.log(hi); }); This code however is displaying
I'm trying to remove (from a string) only the duplicates that occur sequentially. That
I am trying to remove duplicates based on 'duplicate_check' for the following array. It
I am trying to remove the duplicates from a list I binding to a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.