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 8571567
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T18:48:36+00:00 2026-06-11T18:48:36+00:00

I think I found a potential bug in TListView. Steps to reproduce: Create a

  • 0

I think I found a potential bug in TListView.

Steps to reproduce:
Create a new VCL Forms application, add a TListView, set it`s ViewStyle to vsReports.
Add two buttons

button1:

procedure TForm1.Button1Click(Sender: TObject);
var
  lCol: TListColumn;
begin
  lcol :=   ListView1.Columns.Add;
  lcol.Caption := 'name';
  lcol :=   ListView1.Columns.Add;
  lcol.Caption := 'name2';
  lcol :=   ListView1.Columns.Add;
  lcol.Caption := 'name3';
end;

button2:

procedure TForm1.Button2Click(Sender: TObject);
begin
  ListView1.Columns.Delete(1);
end;

Result:
The column is deleted, but the caption of the last column gets lost. This also happens, when adding more columns and deleting a column that is between others (or deleting the first column). The caption of the last column is always empty.

I’m using XE3. Is there anything I missed?

Thanks

edit:
QC link

potential duplicate

  • 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-06-11T18:48:37+00:00Added an answer on June 11, 2026 at 6:48 pm

    There’s more to this then what’s reported in the question (more at the end).

    This is related with a previous question of yours. That question involved the listview control losing the mapping between columns and items/subitems when you moved a column after adding a column. I proposed a possible fix for comctrls.pas which involved preserving FOrderTags of columns when they are moved. The VCL had ‘FOrderTag’s built from the ground-up whenever a column is moved – disregarding any current positioning of the columns.

    What happens then is, you file a bug report, submit the possible fix as a workaround, and it gets checked-in exactly as is. The problem now you discover is, when we preserve FOrderTag of each column, and then remove a column from the middle, we create a hole – they are not sequential any more (say we have columns 0, 1 and 2 with respective order tags, remove column 1 and now we have 2 columns with order tags 0 and 2). Apparently the native control does not like this.

    Again modifying the VCL, we can remove any possible hole when we are removing a column. The below seems to take care of the missing caption and the AV when you resize/move the column with the missing caption mentioned in a comment to the question.

    destructor TListColumn.Destroy;
    var
      Columns: TListColumns;
      i: Integer; //+
    begin
      Columns := TListColumns(Collection);
      if TListColumns(Collection).Owner.HandleAllocated then
        ListView_DeleteColumn(TListColumns(Collection).Owner.Handle, Index);
    //{+
      for i := 0 to Columns.Count - 1 do
        if Columns[i].FOrderTag > FOrderTag then
          Dec(Columns[i].FOrderTag);
    //}
      inherited Destroy;
      Columns.UpdateCols;
    end;
    

    Now if we come back to what’s not reported in the question, if you had been inserted some subitems, you’d have noticed that they are preserving their positions, IOW the mapping between columns and subitems are lost. There’s the probability that your view is different then mine on this, but I think the subitems of the deleted column should get lost. Unfortunately I couldn’t figure out a way to achieve this.


    edit: I cannot think of anything to easily integrate/fix in the VCL. There’s nothing stopping you from deleting the first inserted column. This one corresponds to the items, if we delete the items, all subitems will also be taken out. The current implementation in VCL is that in fact no item data is deleted when you remove a column. You can verify this by adding a column after you remove one, subitems will magically appear under the new column.

    Anyway, what I can suggest you to is to delete the subitems of a removed column manually. Below is an example of a utility procedure to delete a column and its corresponding subitems:

    procedure ListViewDeleteColumn(ListView: TListView; Col: Integer);
    var
      i: Integer;
      ColumnOrder: array of Integer;
    begin
      SetLength(ColumnOrder, ListView.Columns.Count);
      ListView_GetColumnOrderArray(
            ListView.Handle, ListView.Columns.Count, PInteger(ColumnOrder));
      Assert(ColumnOrder[Col] <> 0, 'column with items cannot be removed');
    
      for i := 0 to ListView.Items.Count - 1 do
        if Assigned(ListView.Items[i].SubItems) and
            (ListView.Items[i].SubItems.Count >= Col) then
        ListView.Items[i].SubItems.Delete(ColumnOrder[Col] - 1);
    
      ListView.Columns.Delete(Col);
    end;
    

    If you decide to delete the first column, decide what you’ll do with items/subitems and rebuild them.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What if I think, that I found a bug in an open-source-app? What steps
I've found what I think may be a bug with Ivar and Objective-C runtime.
I'm trying to create a ruby on rails ecommerce application, where potential customers will
I'm not very used to programming with flags, but I think I just found
Today I found LiquiBase project and I think it is very interesting. I would
I think all of the tutorials I found are from before you could use
I found a way to write the if statement in another way (I think)
I really think that here ill found my answers... I try to make a
I found the regular expression for MM/DD/YYYY at http://www.regular-expressions.info/regexbuddy/datemmddyyyy.html but I don't think I
Searching here I found that this question was already asked , but I think

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.