I have a Delphi / FireMonkey app (Delphi 10.2 Tokyo) that contains 2 TListView components. I’m encountering a problem where the second list view causes an Access Violation when I try to populate it… but only on certain machines.
After the user selects a category (which is what the first ListView is for), I populate the 2nd listview. I do it like this:
lvTransactions.Items.Clear;
lvTransactions.BeginUpdate;
for i := 1 to Transactions.Count do
begin
tx := Transactions[i-1];
lvi := lvTransactions.Items.Add;
lvi.TagString := tx.txid;
//AV on this line
lviDate := lvi.Objects.FindObjectT<TListItemText>(‘Date’);
lviDate.Text := FormatDateTime( ‘yyyy-mm-dd hh:nn:ss’, tx.timestamp);
//assigns more values here
//…
end
lvTransactions.EndUpdate;
Going through the remote debugger on one of the machines that has the problem, I found that it is AV’ing on the line:
lviDate := lvi.Objects.FindObjectT<TListItemText>(‘Date’);
Specifically, when the code tries to access the Objects list of the ListViewItem. The ListViewItem’s Objects list is nil, causing the AV.
//from the FMX code for TListViewItem
function TListViewItem.GetViewObjects: TListViewItemObjects;
begin
CreateObjects; //<—- THIS AV’s
Result := TListViewItem.TListViewItemObjects(inherited View);
end;
On my development Desktop, the above works flawlessly. On a pair of laptops I test with, I get an AV every time.
I tried moving some of the code into the OnUpdatingObjects event, and that also still AV’d. Basically, any time the Objects list is referenced, it AV’s.
Am I doing something wrong with the TListView, or is this a problem with it?