SiComponents Home Page SiComponents Forums
Here you will be able to get help and share your experience
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Odd behavior on deleting task.

 
Post new topic   Reply to topic    SiComponents Forums Forum Index -> VCL Scheduling Agent
View previous topic :: View next topic  
Author Message
rbaroniunas



Joined: 25 Dec 2019
Posts: 4

PostPosted: Wed Dec 25, 2019 3:49 pm    Post subject: Odd behavior on deleting task. Reply with quote

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 ?
Back to top
View user's profile Send private message
isiticov
Site Admin


Joined: 21 Nov 2002
Posts: 2184

PostPosted: Thu Dec 26, 2019 4:18 am    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
rbaroniunas



Joined: 25 Dec 2019
Posts: 4

PostPosted: Sat Dec 28, 2019 4:22 pm    Post subject: Reply with quote

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 ?
Back to top
View user's profile Send private message
rbaroniunas



Joined: 25 Dec 2019
Posts: 4

PostPosted: Sat Dec 28, 2019 7:20 pm    Post subject: Reply with quote

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;
Back to top
View user's profile Send private message
isiticov
Site Admin


Joined: 21 Nov 2002
Posts: 2184

PostPosted: Sun Dec 29, 2019 2:49 am    Post subject: Reply with quote

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?
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    SiComponents Forums Forum Index -> VCL Scheduling Agent All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by p h p B B  © 2001, 2005 p h p B B  Group