Recent

Author Topic: Virtual TListView  (Read 31770 times)

Leledumbo

  • Hero Member
  • *****
  • Posts: 8352
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Virtual TListView
« Reply #15 on: January 18, 2011, 07:14:18 pm »
Quote
With my TListView kludge, it takes about ~4 seconds to add 10000 rows, and another ~4 to delete them. Not great, but not a deal breaker.
Ensure to put the addition and deletion code inside BeginUpdate and EndUpdate method, that would prevent the control from redrawing while updating its contents.

Phil

  • Hero Member
  • *****
  • Posts: 2737
Re: Virtual TListView
« Reply #16 on: January 18, 2011, 07:32:39 pm »
I tried out TOvcVirtualListBox, but will stick with TListView for now. TOvcVirtualListBox is speedy, but has non-standard tabbed columns and appearance, and I was having trouble with the vertical scrollbar and multiple selections.

What "trouble" were you having? Remember that with MultiSelect you have to set and implement the OnSelect and OnIsSelected event handlers. See p. 108 and elsewhere in Orpheus.pdf.

Not sure what you mean by "non-standard". Much of LCL looks non-standard on Mac. If Apple HIG are a requirement, Cocoa would be better than LCL.

Thanks.

-Phil

VTwin

  • Hero Member
  • *****
  • Posts: 1037
  • Former Turbo Pascal 3 user
Re: Virtual TListView
« Reply #17 on: January 21, 2011, 05:34:16 pm »
Ensure to put the addition and deletion code inside BeginUpdate and EndUpdate method, that would prevent the control from redrawing while updating its contents.

Thanks very much Leledumbo.

I'm not sure what the "BeginUpdate" and "EndUpdate" methods are though.
« Last Edit: January 21, 2011, 06:07:52 pm by Frederick »
“Talk is cheap. Show me the code.” -Linus Torvalds

Free Pascal Compiler 3.2.0
macOS 10.13.6: Lazarus 2.0.12 (64 bit Cocoa)
Ubuntu 18.04.3: Lazarus 2.0.12 (64 bit on VBox)
Windows 7 Pro SP1: Lazarus 2.0.12 (64 bit on VBox)

VTwin

  • Hero Member
  • *****
  • Posts: 1037
  • Former Turbo Pascal 3 user
Re: Virtual TListView
« Reply #18 on: January 21, 2011, 06:00:36 pm »
What "trouble" were you having? Remember that with MultiSelect you have to set and implement the OnSelect and OnIsSelected event handlers. See p. 108 and elsewhere in Orpheus.pdf.

Not sure what you mean by "non-standard". Much of LCL looks non-standard on Mac. If Apple HIG are a requirement, Cocoa would be better than LCL.

Thanks Phil.

I implemented the OnSelect and OnIsSelected event handlers with MultiSelect in the TOvcVirtualListBox demo. OvcVirtualListBox1Select starts firing when the mouse y coordinate is in the range of the listbox, without pressing the mouse button or being over the listbox at all. OvcVirtualListBox1IsSelected did not fire.

Also, I could not get the vertical scrollbar to appear manually or automatically, I tried all of the "ScrollBars" values without luck.

I should not have said "non-standard". I need a control that has some spreadsheet-type characteristics, such as resizable columns and editable cells. I don't need Apple HIG, just something that will be familiar to a Mac or Windows Excel or OpenOffice.org spreadsheet user. I will need to compile to Windows as well as Mac. The virtual TListView seems almost perfect, but maybe has a few small bugs I can help kill.

Cheers,
Frederick
« Last Edit: January 21, 2011, 06:09:23 pm by Frederick »
“Talk is cheap. Show me the code.” -Linus Torvalds

Free Pascal Compiler 3.2.0
macOS 10.13.6: Lazarus 2.0.12 (64 bit Cocoa)
Ubuntu 18.04.3: Lazarus 2.0.12 (64 bit on VBox)
Windows 7 Pro SP1: Lazarus 2.0.12 (64 bit on VBox)

Leledumbo

  • Hero Member
  • *****
  • Posts: 8352
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Virtual TListView
« Reply #19 on: January 21, 2011, 08:36:40 pm »
Quote
I'm not sure what the "BeginUpdate" and "EndUpdate" methods are though
http://www.festra.com/eng/tip-beginupdate.htm

VTwin

  • Hero Member
  • *****
  • Posts: 1037
  • Former Turbo Pascal 3 user
Re: Virtual TListView
« Reply #20 on: January 22, 2011, 12:10:37 am »
http://www.festra.com/eng/tip-beginupdate.htm

Thanks. That seemed like a great tip, and I was excited to try it out. I tried this:

Code: [Select]
procedure TForm1.SetListViewCount(count: integer);
begin
  ListView1.Items.BeginUpdate;
  while ListView1.Items.Count > 0 do
    ListView1.Items.Delete(ListView1.Items.Count-1);
  while ListView1.Items.Count < count do
    ListView1.Items.Add;
  ListView1.Items.EndUpdate;
  ListView1.Items[-1];
  ListView1.Refresh;
end;

Unfortunately, it did not seem to change the time. Still ~8 seconds to delete and add 10000 items.

Cheers,
Frederick
“Talk is cheap. Show me the code.” -Linus Torvalds

Free Pascal Compiler 3.2.0
macOS 10.13.6: Lazarus 2.0.12 (64 bit Cocoa)
Ubuntu 18.04.3: Lazarus 2.0.12 (64 bit on VBox)
Windows 7 Pro SP1: Lazarus 2.0.12 (64 bit on VBox)

Leledumbo

  • Hero Member
  • *****
  • Posts: 8352
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Virtual TListView
« Reply #21 on: January 22, 2011, 12:19:28 am »
What if you call BeginUpdate of the ListView? e.g. change ListView1.Items.BeginUpdate to ListView1.BeginUpdate, do the same for EndUpdate. One of my projects use this so I really remember that I got a big speed enhancement.

Phil

  • Hero Member
  • *****
  • Posts: 2737
Re: Virtual TListView
« Reply #22 on: January 22, 2011, 03:32:32 am »
I implemented the OnSelect and OnIsSelected event handlers with MultiSelect in the TOvcVirtualListBox demo. OvcVirtualListBox1Select starts firing when the mouse y coordinate is in the range of the listbox, without pressing the mouse button or being over the listbox at all. OvcVirtualListBox1IsSelected did not fire.

Also, I could not get the vertical scrollbar to appear manually or automatically, I tried all of the "ScrollBars" values without luck.

I can't reproduce any of the problems you report. See if attached example works for you.

Thanks.

-Phil


VTwin

  • Hero Member
  • *****
  • Posts: 1037
  • Former Turbo Pascal 3 user
Re: Virtual TListView
« Reply #23 on: January 22, 2011, 04:26:20 pm »
What if you call BeginUpdate of the ListView? e.g. change ListView1.Items.BeginUpdate to ListView1.BeginUpdate, do the same for EndUpdate. One of my projects use this so I really remember that I got a big speed enhancement.

Thanks Leledumbo. I just tried calling the ListView1 methods instead as you suggest, but it doesn't make any difference. I didn't do an exact speed test, but again it is ~8 seconds.
“Talk is cheap. Show me the code.” -Linus Torvalds

Free Pascal Compiler 3.2.0
macOS 10.13.6: Lazarus 2.0.12 (64 bit Cocoa)
Ubuntu 18.04.3: Lazarus 2.0.12 (64 bit on VBox)
Windows 7 Pro SP1: Lazarus 2.0.12 (64 bit on VBox)

VTwin

  • Hero Member
  • *****
  • Posts: 1037
  • Former Turbo Pascal 3 user
Re: Virtual TListView
« Reply #24 on: January 22, 2011, 04:40:13 pm »
I can't reproduce any of the problems you report. See if attached example works for you.

Thanks.

-Phil

I apologize for my denseness Phil. The example you gave works wonderfully.

I made a fresh copy of the 'TestVLB' project in 'OrpheusForLaz_20110115' and played with it some more. I must have mangled something in the old copy, because now I can get the scrollbars to work properly.

The strange behavior I reported was because I was not using the OvcVirtualListBox1IsSelected and OvcVirtualListBox1Select correctly. Your example is extremely clear and helpful.

Thanks, I appreciate the help.
“Talk is cheap. Show me the code.” -Linus Torvalds

Free Pascal Compiler 3.2.0
macOS 10.13.6: Lazarus 2.0.12 (64 bit Cocoa)
Ubuntu 18.04.3: Lazarus 2.0.12 (64 bit on VBox)
Windows 7 Pro SP1: Lazarus 2.0.12 (64 bit on VBox)

VTwin

  • Hero Member
  • *****
  • Posts: 1037
  • Former Turbo Pascal 3 user
Re: Virtual TListView
« Reply #25 on: January 22, 2011, 04:51:25 pm »
Also checking out some of the other Orpheus controls now, some nice things in there.
“Talk is cheap. Show me the code.” -Linus Torvalds

Free Pascal Compiler 3.2.0
macOS 10.13.6: Lazarus 2.0.12 (64 bit Cocoa)
Ubuntu 18.04.3: Lazarus 2.0.12 (64 bit on VBox)
Windows 7 Pro SP1: Lazarus 2.0.12 (64 bit on VBox)

Phil

  • Hero Member
  • *****
  • Posts: 2737
Re: Virtual TListView
« Reply #26 on: January 23, 2011, 12:46:56 am »
I noticed that non-contiguous selection did not work in TOvcVLB on Mac. On Windows, this is done with Ctrl+click, but that's the same as right-click on Mac since it used to have only a one-button mouse. Cmd+click now works on Mac in TOvcVLB.

If you find other problems, please file bug reports. In Mantis, you can use "Lazarus CCR" section for add-on packages like Orpheus.

Like LCL, there are probably still quite a few bugs in Orpheus, many undoubtedly discovered but unreported.

Thanks.

-Phil

d7_2_laz

  • Full Member
  • ***
  • Posts: 182
Re: Virtual TListView
« Reply #27 on: June 24, 2021, 01:44:27 pm »
It appears to me that the bug that had been mentioned 10 years ago at the beginning of the article
(wrong virtuallistview first row refresh when changing item count) is still alive.

I did struggle some hours with the following strange behaviour:
virtual listview. listview contains 2 rows. Try to delete the first row.
For a short period / delay of time, the wrong one (the second row) appears to be deleted.

Berause the first row (=>  after deletion, the previous second row will be tne new first row now)
resp. the first row's content will be wrongly refreshed.

Until i found the circumvention within this article (see reply #9), that did fix the strange behaviour:

Code: Pascal  [Select][+][-]
  1.      svi :=  Items[i].Index;
  2.      DeleteArrayItem(FFlieInfo, svi);
  3.      Dec(FFlieInfoCount);
  4.      Delete(Items[i]);
  5. // Due to Lazarus bug related to wrong virtuallistview first row refresh / with workaround:
  6. // https://forum.lazarus.freepascal.org/index.php/topic,11796.msg59695.html#msg59695
  7.      Items.Count := 0;    // Workaround
  8.      Items.Count := FFlieInfoCount;
  9.      Self.Refresh;        // Workaround

ASerge

  • Hero Member
  • *****
  • Posts: 1815
Re: Virtual TListView
« Reply #28 on: June 25, 2021, 09:21:10 pm »
If you are actually using ListView in virtual mode (.OwnerData = True), then forget about Insert, Delete and other ListView.Items functions. Do this not with it, but with the data source that is used to populate the ListView in the OnData event. And then just adjust the value of ListView.Items.Count.

d7_2_laz

  • Full Member
  • ***
  • Posts: 182
Re: Virtual TListView
« Reply #29 on: June 26, 2021, 11:10:22 am »
That's exactly what i did (removing the record from the array keeping the data; decrementing it's counter;
assigning the counter to Items.Count).
But the tricki is at least to use the "Refresh". Without that, embedding in BeginUpdate/EndUpdate or forcing a repaint on Items[0] is not enough: for a second or so it looks like having the wrong row deleted (#2 instead of #1, where #1 is the candidate for deletion in this scenario). Inspecting the item values at that point, Items[0] appears to still keep it's old value).

Never mixed an Items "Add" with the ownerdata technique, but, right, had used a "Delete" (without problems with Delphi).
My lessons learnt is to use the Refresh in this context. Right - i can omit the "Delete(Items" here (retested).

 

TinyPortal © 2005-2018