Watch, Follow, &
Connect with Us
Public Report
Report From: Delphi-BCB/VCL/Win 32 Controls/TListView    [ Add a report in this area ]  
Report #:  85130   Status: Closed
Several TListView properties has wrong values
Project:  Delphi Build #:  14.0.3593.25826
Version:    14.0 Submitted By:   Hans Christoffersen
Report Type:  Issue Date Reported:  6/4/2010 5:21:38 AM
Severity:    Serious / Highly visible problem Last Updated: 4/23/2013 8:18:01 AM
Platform:    All platforms Internal Tracking #:   277618
Resolution: Duplicate (Resolution Comments) Resolved in Build: : XE4
Duplicate of:  87943
Voting and Rating
Overall Rating: No Ratings Yet
0.00 out of 5
Total Votes: None
Description
When TListView.ViewStyle <> vsIcon, the following properties has wrong values when accessed from TForm.Create:

Items.Count : 0

This was not an issue in Delphi 2009

----------

The following properties has always wrong values:

TListView.VisibleRowCount

This was not an issue in Delphi 2009


Added by Sysop
<<<<<<<<<<<<<<<<<<<<
I think this issue is due to lazy initialization to increase speed. So, we need to access Handle property before reading Items.Count property as below.
-------------
procedure TForm1.FormCreate(Sender: TObject);
begin
  ListView1.Handle;  // <<--- to avoid lazy initialization
  ShowMessage(IntToStr(ListView1.Items.Count));
end;
-------------
>>>>>>>>>>>>>>>>>>>>
Steps to Reproduce:
1) Create a new VCL Forms Application
2) Place a TListView on the form
3) Add some items to the ListView
4) Change ViewStyle to vsReport, vsList or vsSmallIcon
5) Access Items.Count from TForm.Create
6) Property Count will have a value of 0

----------

1) Create a new VCL Forms Application
2) Place a TListView on the form
3) Add some items to the ListView
4) Access VisibleRowCount
5) Property VisibleRowCount will have a wrong value
Workarounds
When TListView.ViewStyle <> vsIcon, Items.Count has a value of 0 when accessed from TForm.Create:

Access Items.Count from TForm.Show

----------

VisibleRowCount has always a wrong value:

None
Attachment
None
Comments

Tomohiro Takahashi at 6/8/2010 10:42:59 PM -
> 6) Property Count will have a value of 0
I think your issue is due to lazy initialization to increase speed.
So, please try to access Handle property before reading Items.Count property as below.
-------------
procedure TForm1.FormCreate(Sender: TObject);
begin
  ListView1.Handle;  // <<--- to avoid lazy initialization
  ShowMessage(IntToStr(ListView1.Items.Count));
end;
-------------

Hans Christoffersen at 6/24/2010 2:07:47 AM -
Seems to work

Server Response from: ETNACODE01