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 

query task.flags[]

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



Joined: 12 Sep 2005
Posts: 5
Location: Camarillo CA. USA

PostPosted: Tue Sep 13, 2005 5:08 am    Post subject: query task.flags[] Reply with quote

Hello,

1. How can I test the TaskItem.Flags to see if they aready include [tfDisabled]?

2. The snippet included below tirns on the scheduler but it also generates an ugly AV. Can you tell what I am doing wrong?

Thanks
Sam
=============================================

procedure Tmaxmain.AutomaticallyUploadBackup(
Sender: TObject);
var
Trigger: TTrigger;
Details: TTriggerDetails;
S,ulogin: string;
x:smallint;
begin
ulogin:='';
dialogs.InputQuery('Windows Login','Please Enter Login.',ulogin);
TaskItem := TaskScheduler1.ActivateTask('iNetBackup');
if TaskItem = nil then
try
TaskItem := TaskScheduler1.CreateNewItem('iNetBackup');
if (Trim(sysinfo1.Username) = EmptyStr) and (Trim(ulogin) = EmptyStr) then
TaskItem.Flags:=TaskItem.Flags - [tfRunOnlyIfLoggedOn]
else
TaskItem.Flags:=TaskItem.Flags + [tfRunOnlyIfLoggedOn];
TaskItem.ApplicationName :='c:\hunni\inetbkup.exe';
TaskItem.Parameters := '-runtask "' + 'c:\hunni\inetbkup.exe'+ '"';
TaskItem.SetAccountInformation(sysinfo1.Username,ulogin);
Trigger := TaskItem.Triggers.Add;
Trigger.TriggerType := ttAtStartup;
Trigger.BeginDate := Now;
TaskItem.Save;
finally
end
else
try
x:=-1;
repeat
inc(x);
until taskscheduler1.items[x].Name='iNetBackup';
taskitem:=taskscheduler1.items[x];
TaskItem.Flags := TaskItem.Flags - [tfDisabled];
TaskItem.Save;
finally
end;

end;
Back to top
View user's profile Send private message Visit poster's website
isiticov
Site Admin


Joined: 21 Nov 2002
Posts: 2096

PostPosted: Tue Sep 13, 2005 6:17 am    Post subject: Reply with quote

1. This code snippet inverts the tfDisabled flag:
Code:
    if tfDisabled in TaskItem.Flags then
      TaskItem.Flags := TaskItem.Flags - [tfDisabled]
    else
      TaskItem.Flags := TaskItem.Flags + [tfDisabled];

2. If you specify at wich line you get AV error it would help. Anyway please find below the working sample. We've changed a little code by eliminating sysinfo1 reference, since we don't have it Smile
Code:
procedure TForm1.Button1Click(Sender: TObject);
var
  Trigger: TTrigger;
//  Details: TTriggerDetails;
//  S,ulogin: string;
//  x:smallint;
  TaskItem: TTaskItem;
begin
  TaskScheduler1.Open;
  TaskScheduler1.Refresh;
//  ulogin:='';
//  dialogs.InputQuery('Windows Login','Please Enter Login.',ulogin);
  TaskItem := TaskScheduler1.ActivateTask('iNetBackup');
  if TaskItem = nil then
  begin
    TaskItem := TaskScheduler1.CreateNewItem('iNetBackup');
//    if (Trim(sysinfo1.Username) = EmptyStr) and (Trim(ulogin) = EmptyStr) then
    TaskItem.Flags:=TaskItem.Flags - [tfRunOnlyIfLoggedOn];
//    else
//      TaskItem.Flags:=TaskItem.Flags + [tfRunOnlyIfLoggedOn];
    TaskItem.ApplicationName :='c:\hunni\inetbkup.exe';
    TaskItem.Parameters := '-runtask "' + 'c:\hunni\inetbkup.exe'+ '"';
    TaskItem.SetAccountInformation('', '');
    Trigger := TaskItem.Triggers.Add;
    Trigger.TriggerType := ttAtStartup;
    Trigger.BeginDate := Now;
    TaskItem.Save;
  end
  else
  begin
{    x:=-1;
    repeat
      inc(x);
    until taskscheduler1.items[x].Name='iNetBackup';
    taskitem:=taskscheduler1.items[x];}
    TaskItem.Activate;
    if tfDisabled in TaskItem.Flags then
      TaskItem.Flags := TaskItem.Flags - [tfDisabled]
    else
      TaskItem.Flags := TaskItem.Flags + [tfDisabled];
    TaskItem.Save;
  end;
end;

Hope this helps.
Back to top
View user's profile Send private message
samh



Joined: 12 Sep 2005
Posts: 5
Location: Camarillo CA. USA

PostPosted: Tue Sep 13, 2005 8:11 pm    Post subject: query flags[] Reply with quote

Hello,

I used the code you suggested. It works much better but I am still getting the AV. The AV happens in the saTask.pas unit, in the finction GetWorkingDirectory, on the call to OLECheck. I was unable to debug into OLECheck. I get the AV EOLESYSTEM ERROR "Access is Denied".

Even with the AV , the code still sets the scheduler. There is another issue with the scheduler setting I would like to resolve: The run time is alwasy set to the time of day I enter the task into the scheduler. What I want is for the scheduler to start running the app immediately instead of waiting until a specific time of day.

My code is below.

Thnaks
Sam
===========================================
procedure Tmaxmain.Button1Click(
Sender: TObject);
var
Trigger:TTrigger;
TaskItem: TTaskItem;
begin
TaskScheduler1.Open;
TaskScheduler1.Refresh;
TaskItem := TaskScheduler1.ActivateTask('iNetBackup');
if TaskItem = nil then
begin
TaskItem := TaskScheduler1.CreateNewItem('iNetBackup');
TaskItem.Flags:=TaskItem.Flags - [tfRunOnlyIfLoggedOn];
TaskItem.ApplicationName :='c:\hunni\inetbkup.exe';
TaskItem.Parameters := '-runtask "' + 'c:\hunni\inetbkup.exe'+ '"';
TaskItem.SetAccountInformation('', '');
Trigger := TaskItem.Triggers.Add;
Trigger.TriggerType := ttAtStartup;
Trigger.BeginDate := Now;
TaskItem.Save;
end
else
begin
TaskItem.Activate;
if tfDisabled in TaskItem.Flags then
TaskItem.Flags := TaskItem.Flags - [tfDisabled];
TaskItem.Save;
end;
end;
Back to top
View user's profile Send private message Visit poster's website
isiticov
Site Admin


Joined: 21 Nov 2002
Posts: 2096

PostPosted: Wed Sep 14, 2005 5:18 am    Post subject: Reply with quote

You can use TaskItem.Run method to execute task immediately.

Hope this helps.
Back to top
View user's profile Send private message
samh



Joined: 12 Sep 2005
Posts: 5
Location: Camarillo CA. USA

PostPosted: Wed Sep 14, 2005 5:30 pm    Post subject: AV when setting scheduler Reply with quote

Hello,

I was hoping to receive an answer about the AV as well as the time setting. I guess on the time setting I will need to set the start time to 6 AM since it appears the scheduler takes the time of task entry as the start time if no start time is stated.

Regards
Sam
Back to top
View user's profile Send private message Visit poster's website
isiticov
Site Admin


Joined: 21 Nov 2002
Posts: 2096

PostPosted: Thu Sep 15, 2005 8:03 am    Post subject: Re: AV when setting scheduler Reply with quote

samh wrote:
I was hoping to receive an answer about the AV as well as the time setting. I guess on the time setting I will need to set the start time to 6 AM since it appears the scheduler takes the time of task entry as the start time if no start time is stated.


In the provided code there is no any call for WorkingDirectory property and it must execute without any problems. If you access to WorkingDirectory property in other place of code please note: it must be called only after saving or activating the task item, before that it will contain invalid data.
To set the start time you should use StartTime property, but in your Exclamation question you asked how to run task immediately, and the answer was provided.

Hope this helps.
Back to top
View user's profile Send private message
samh



Joined: 12 Sep 2005
Posts: 5
Location: Camarillo CA. USA

PostPosted: Thu Sep 15, 2005 5:35 pm    Post subject: AV Reply with quote

Sorry to be a pest;

I have solved the AV issue. I added saTask.pas to my project and when I did I got an error that saDialogs was compiled with a different version of saTask. So I added saDialogs to my project (both from the source folder). This stopped the AV so I guess I was having some kind of conflict with holdover code from the demo mixing with code form the licensed product.

Now I still need to solve the starttime issue. I do not want a starttime. I want the app to start running as soon as the computer is booted. I am unable to get the schedule to NOT include a startime (which is always the time of day when the app was entered into the scheduler).

Once again I have included my code below.
Thanks
Sam
========================================
procedure Tbutton1click(Sender: TObject);
var
Trigger:TTrigger;
TaskItem: TTaskItem;
begin
TaskScheduler1.Open;
TaskScheduler1.Refresh;
TaskItem := TaskScheduler1.ActivateTask('iNetBackup');
if TaskItem = nil then
begin
TaskItem := TaskScheduler1.CreateNewItem('iNetBackup');
TaskItem.WorkingDirectory:='C:\Hunni';
TaskItem.Flags:=TaskItem.Flags - [tfRunOnlyIfLoggedOn];
TaskItem.ApplicationName :='c:\hunni\inetbkup.exe';
TaskItem.Parameters := '-runtask "' + 'c:\hunni\inetbkup.exe'+ '"';
TaskItem.SetAccountInformation('', '');
Trigger := TaskItem.Triggers.Add;
Trigger.TriggerType := ttAtStartup;
Trigger.BeginDate := Now;
TaskItem.Save;
end
else
begin
TaskItem.Activate;
if tfDisabled in TaskItem.Flags then
TaskItem.Flags := TaskItem.Flags - [tfDisabled];
TaskItem.Save;
end;
end;
Back to top
View user's profile Send private message Visit poster's website
isiticov
Site Admin


Joined: 21 Nov 2002
Posts: 2096

PostPosted: Fri Sep 16, 2005 9:28 am    Post subject: Reply with quote

....
TaskItem.SetAccountInformation('', '');
Trigger := TaskItem.Triggers.Add;
Trigger.TriggerType := ttAtStartup;
Trigger.BeginDate := Now;
Trigger.Enabled := True;
Trigger.UpdateTrigger;

TaskItem.Save;
.....

Please add lines in bold to your source. Ther origin: trigger needs to be enabled and you must call UpdateTrigger method after all settings are set.

or
TaskItem.Triggers.UpdateTriggers;
TaskItem.Save;


Hope this helps.
Back to top
View user's profile Send private message
samh



Joined: 12 Sep 2005
Posts: 5
Location: Camarillo CA. USA

PostPosted: Fri Sep 16, 2005 10:09 pm    Post subject: Got it Reply with quote

Thanks for your help. I am now getting the exact results I purchased your product for.

Reagrds
Sam
Back to top
View user's profile Send private message Visit poster's website
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