Page 1 of 1

Problem in Enable/Disable a Task

Posted: Wed May 11, 2005 3:33 pm
by partha
Hello,

I am having problem in enabling/disabling a task. I am using the folowing code but the changes are not getting saved:

var
Index : Integer;
Task: TTaskItem;
begin
for Index := 0 to Scheduler.Count - 1 do begin
Task := Scheduler.Items[Index];
Task.Activate;
if SetActive then //SetActive is procedure parameter
Task.Flags := Task.Flags + [tfDisabled]
else
Task.Flags := Task.Flags - [tfDisabled];
Task.Save;
end;
end;


Any help will be appreciated.

thanks and regards,
Partha

Posted: Wed May 11, 2005 7:12 pm
by isiticov
Do you get any error? May be using

Code: Select all

Task.Deactivate(True);
instead of

Code: Select all

Task.Save;
will help? How do you see that changes are not saved? Do you make "refresh"?

Posted: Thu May 12, 2005 3:25 am
by partha
I tried both

Task.Deactivate(True);
and
Task.Save;

None of them work. I do not get an error but the status is not updated.

I am not displaying it to any control so I do not need a refresh.

Posted: Thu May 12, 2005 4:20 am
by isiticov
This really strange. There is no any "problematic" place in your code.
I do not get an error but the status is not updated.
But where do you "see" this status if you don't display it? Directly in Scheduled Tasks? Then Status column doesn't change on adding Disabled flag, but only Schedule and Next Run coulmns indicates Disabled.

Posted: Thu May 12, 2005 4:45 am
by partha
I check directly in windows scheduler. Also with,
Task.EditWorkItem

Posted: Thu May 12, 2005 6:22 am
by isiticov
:) There is small bug in your source and I can suppose it is the origin of problem. Instead of

Code: Select all

if SetActive then //SetActive is procedure parameter 
Task.Flags := Task.Flags + [tfDisabled] 
else 
Task.Flags := Task.Flags - [tfDisabled]; 
shall be used

Code: Select all

if SetActive then //SetActive is procedure parameter 
Task.Flags := Task.Flags - [tfDisabled] 
else 
Task.Flags := Task.Flags + [tfDisabled]; 
Please let us know if this fixes the problem.

Posted: Thu May 12, 2005 7:00 am
by partha
Thanks, it solves this. :)