In my application i have a TListView that list all of the scheduled tasks for the user. When i attempted to delete a task based on a button event i received a access violation (application did not crap out) on an invalid pointer.
The only thing i did was move the lyTasks.Item[Index].Delete from after the DeleteTask Method and the AV went away.
Original (AV on this one).
Task.Activate;
tskScheduler.DeleteTask(Task.Name);
lvTasks.Items[Index].Delete;
New (this works)
lvTasks.Items[Index].Delete;
Task.Activate;
tskScheduler.DeleteTask(Task.Name);
I thought it was very odd by simply moving the ListView delete it works. If i do not have the ListView Delete method, the item remains in the listview.
Is there anything i am doing incorrectly ?
Odd behavior on deleting task.
-
- Posts: 19
- Joined: Wed Dec 25, 2019 2:13 am
-
- Posts: 19
- Joined: Wed Dec 25, 2019 2:13 am
Here is the entire routine
for Index := lvTasks.Items.Count - 1 downto 0 do
if lvTasks.Items[Index].Selected then
begin
Task := TTaskItem(lvTasks.Items[Index].Data);
try
lvTasks.Items[Index].Delete;
Task.Activate;
tskScheduler.DeleteTask(Task.Name);
lvTasks.Refresh;
except
raise EUnexpectedError.Create('TScheduledTasks.sBtnDeleteClick');
end;
end;
for Index := lvTasks.Items.Count - 1 downto 0 do
if lvTasks.Items[Index].Selected then
begin
Task := TTaskItem(lvTasks.Items[Index].Data);
try
lvTasks.Items[Index].Delete;
Task.Activate;
tskScheduler.DeleteTask(Task.Name);
lvTasks.Refresh;
except
raise EUnexpectedError.Create('TScheduledTasks.sBtnDeleteClick');
end;
end;