I have a ListView:TListview on my form ,and, I add many values(approximately 25k TListViewItem) ,which works quite fast,but when I call Listview.Clear,the program freezes.I checked it with debugger,it won't step that line.
My question is: how do I solve my problem? If creating so many items in less than a second is possible,why deleting them takes forever(I waited over 5 minutes)?
Have you tried enclosing your call to Clear in a BeginUpdate/EndUpdate block:
listview.Items.BeginUpdate;
try
listview.Items.Clear;
finally
listview.Items.EndUpdate;
end;
Adding/Removing items in a listview (or various other controls, e.g. listbox) triggers a GUI update of the control for each and every item that is added/removed. For a listview in particular, this can be quite expensive and for 25,000 items the overhead would be significant.
Admittedly 5 minutes does sound excessive, but this would be the first thing I would try.
The first thing I'd try is wrap your call to Clear with BeginUpdate/EndUpdate.
ListView1.Items.BeginUpdate;
ListView1.Clear;
ListView1.Items.EndUpdate;
Do you have any events attached to the ListView, and are they firing as the list is being cleared?
as the others noted a BeginUpdate .... EndUpdate will greatly increase performance, however I would really suggest you move your code to use VirtualTreeView. It's a hybrit tree/ListView which will add up to 1m nodes in less than a second (actually that depends on the processor, but you get the idea).
It's a bit harder to learn in the beginning but once you get used to it you'll find it "easy" to work with. I personally whenever I need many rows in a ListView or TreeView look no further than VirtualTreeView. Oh, and forgot to mention that on top of it, it's free. Try it from : http://soft-gems.net/
John, it should not be longer to clear than to add the 25k items.
I wonder if you load it while it is not visible (automatically disabling updates), but clear it when it is visible where each item deletion triggers an update.
I don't know whether I should delete this question or not,I believe it's not going to be in any use to anyone else,but I prefer to keep it for awhile at least for you,who answered.
The problem was that I used a component inheriting from TListView,I thought It wouldn't be a problem so I decided to say TListView,but I was wrong.
I upvoted all your answers, please excuse my ignorance - I'm new.
Related
I used to use "iter_dialogs" to get a list of available chats. But this method has stopped working. Can you suggest an alternative? And is it possible to get a list of report-bots to write to them later? I will be very glad of any help.
iter_dialogs() doesn't work anymore, as it has been replaced by get_dialogs(). See Pyrogram's Release Notes for v2:
Iter_ methods have been removed:* This means there is now only one way of iterating through items by using the respective get_* methods which are all turned into generators. Some of the methods have been renamed as well:
iter_history becomes get_chat_history().
iter_chat_members becomes get_chat_members().
iter_dialogs becomes get_dialogs().
iter_profile_photos becomes get_chat_photos().
As for your second question about report bots, I have no idea what you're talking about there. You might want to edit your question to add more detail.
I'm trying to figure out how to check whether the page has fully loaded in Playwright. await page.waitForLoadState('networkidle'); doesn't always work for me on Javascript-heavy sites. I've resorted to taking a screenshot base64, waiting 100 ms, taking a new screenshot, and comparing whether those are the same. However this doesn't seem ideal, is there any way to ask Playwright when the last animation frame was redrawn?
There are several options that may help you.
1. Solution 1:
First, you can maybe determine which element is loading last, and then go with
page.waitForSelector('yourselector')
or even wait for multiple selectors to appear
page.waitForSelector('yourselector1','yourselector2')
2. Solution 2
page.waitForLoadState('domcontentloaded')
Because
page.waitForLoadState('networkidle')
by default will wait for network event and if 0.5 seconds nothing is network trafficking it will say, I am no longer need to wait. And that is why you maybe have stohastic beh.
If the given solution doesn't work for you, you can try with locator.
page.locator(selector[, options])
It has multiple api like locator.isDisabled or locator.waitFor([options]) or locator.isVisible([options]) or locator.frameLocator(selector) ....... a lot more.
see the below link here:
https://playwright.dev/docs/api/class-locator
I've searched a ton and haven't found an answer that seems to address the problem I'm having.
I have a UITableViewController. In the viewDidLoad method I load objects from a database and then call reloadData.
Now generally this works fine. However, now I'm implementing sorting, which is persisted so that the same sorting algorithm is used on the next app launch. Note in all cases, the size of the array backing the section is the same after sorting.
If I use the default sorting method, I get no crash, even though it runs through the same sort > call delegate > reloadTable code path. However, if I use an alternate sorting method, which uses the same code path, I see the table view ask for number of rows, and get the correct number, but then I get this exception. Only the objects are sorted in a different order, so this makes no sense to me.
Also of note is that if I sort the objects (which uses the same code path) after the table has been displayed, it works fine.
This makes no sense to me, and almost seems like a UITableView bug, but I hope it's something I can fix.
My app is open source, so I can link directly to the relevant files:
https://github.com/einsteinx2/iSub/blob/weird_crash/Classes/UI/Reusable/ItemViewController.swift
https://github.com/einsteinx2/iSub/blob/weird_crash/Classes/UI/Reusable/ItemViewModel.swift
The most relevant methods are ItemViewModel.sortAll() and ItemViewController.itemsChanged(viewModel: ItemViewModel)
I've run out of ideas on how to debug this. It just makes no sense.
Some trial and error things I've tried:
Using only one table section
Calling reloadData after a delay to rule out some kind of race condition
Not calling reloadData in my itemsChanged delegate method (still crashes, as reloadData seems to be called automatically by the table view controller)
Nothing seems to make any difference. I'm completely confused how this could be possible. If anyone has any ideas on how I can continue to debug this, or how it may be possible, I'm all ears. Thanks.
EDIT: To make matters more confusing, I have similarly persisted sorting for albums, which use the same ItemViewController, however returning to an album that was previously sorted does not cause a crash, even though it should be doing the exact same thing and running the same code path.
Wow, I finally figured it out and talk about edge case!
Turns out the crash has to do with the table section indexes (the letters on the right hand side), not the actual data loading or sorting.
I was using the unicode bullet character • when not sorted by name. Somehow this worked when you sorted live, but there is some bug in UITableView that causes the internal array of section indexes to be empty when you load the table with that data. I switched to using the black circle character ● and now it no longer crashes.
I think this has to be the smallest change for the most amount of investigation work I've ever done in 8 years of coding for iOS.
Hope this helps some random person in the future. I'll report a bug to Apple, though likely it won't be high priority so who knows if/when they'll fix it.
First, please don't ask me why I need to do this. Unless you can tell me how to convert a TFDDataset directly to a _RecordSet, please, don't ask. :-)
So, this is my question:
Give a TFDDataset, how can I convert that dataset into a TADODataset?
The TFDDataMove component will only move to a FireDac dataset, not to anything else.
What strategy would you recommend? Brute force (iterate over fields and records...) is the only thing I can think of, but perhaps I'm missing some easier or better way.
Thanks.
OK, I ported it to Delphi XE4 and also started adding bookmark support so you can hook it with a TADODataSet and use TDataSource and data-aware controls. There still seems to be a little bug somewhere which causes the dbgrid raise a "grid index out of range" error if you navigate to the last record immediately after switching to the ADO dataset. Anyway, here's what I have.
Merry Christmas, Nick!
ADORecordSet.pas
Test project:
Project1.dpr, Unit1.pas, Unit1.dfm
The auto_complete_for dealio from script.aculo.us is great an all, but is there a way for me to selectively disable the fact that it always auto-selects the first item in the list?
The problem is that, if I want to type my own entry that is new, and novel, I don't want the first item in the list to be auto-selected. The reason is because when I TAB out of the field, it selects, and fills the text box with that first item.
I got around that, somewhat, by making the first item in the list the same as what I'm typing, but that's not perfect either, because the auto_complete list doesn't always update with every keystroke, depending on how fast I type. I've tried setting the list refresh rate to the lowest value (1 millisecond) but no go.
What I really want is an option in "auto_complete_for" that doesn't select that first item at all - the same way that Google Instant doesn't automatically select the first suggested search phrase - you have to arrow-down to select one.
Maybe I can do this via an HTML option that I'm missing?
Looking at the source, there doesn't appear to be an option for that, but I bet if you changed line 284 of controls.js to this.index = -1; it would do what you want.
Otherwise, it might be time to look for a different autocomplete widget.
If your requirements are too far away from the available plugin, then I guess there is no point in tinkering around. Its best to write your own JS code.
You might want to consider this: https://github.com/laktek/jQuery-Smart-Auto-Complete
or this : https://github.com/reinh/jquery-autocomplete
I'll add another alternative that works great with Rails 3:
http://github.com/crowdint/rails3-jquery-autocomplete
I recently implemented auto complete for more than a field for Rails 2.0.2.
The plugin I used is:- https://github.com/david-kerins/auto_complete . Not sure if it supports Rails 3.
I have also encountered issues on implementing the above scenario and have posted questions( Implementing auto complete for more than one field in Rails ; Implementing a OnClick kind of functionality and formatting wrt Rails Partial-Views ) on stackoverflow for the same, I have been lucky on getting things working for me based on my requirement.
Kindly refer to these questions, they might have relevance to your requirement.