Odd behavior on deleting task.

This forum is designated to discuss SiComponents Scheduling Agent.
Post Reply
rbaroniunas
Posts: 6
Joined: Wed Dec 25, 2019 2:13 am

Odd behavior on deleting task.

Post by rbaroniunas »

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 ?

isiticov
Site Admin
Posts: 2207
Joined: Thu Nov 21, 2002 3:17 pm

Post by isiticov »

This is strange. As an idea: may be in your code you do some "background" task like drawing or checking/changing the state icon of list item depending on assigned task or so on? So when the task deleted this causes AV error.

rbaroniunas
Posts: 6
Joined: Wed Dec 25, 2019 2:13 am

Post by rbaroniunas »

Not that i see. The funny thing is when i move the delete method prior to the taskscheduler doing it's delete, the piece works. What exactly is the taskscheduler doing when it deletes a task ?

rbaroniunas
Posts: 6
Joined: Wed Dec 25, 2019 2:13 am

Post by rbaroniunas »

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;

isiticov
Site Admin
Posts: 2207
Joined: Thu Nov 21, 2002 3:17 pm

Post by isiticov »

It doesn't do anything "special". Just deletes the TTaskItem from internal list and then call's Task Service's method to delete the actual task.

P.S. I'm sorry but are you sure that calling lvTasks.Referesh inside a loop is correct?

Post Reply