Solved

can't compile demo from TaskScheduler.zip (www.delphi-jedi.org)

Posted on 2003-11-24
3
813 Views
Last Modified: 2007-12-19
I downloaded TaskScheduler.zip (www.delphi-jedi.org). I loaded the TaskSchDemo.dpr project and tied to compile it. I got the following error when I try to compile the demo:
What am I doing wrong with the setup(I am using Delphi 7)?


[Error] main.pas(202): Constant object cannot be passed as var parameter
[Error] main.pas(890): Constant object cannot be passed as var parameter
[Error] main.pas(891): Constant object cannot be passed as var parameter
[Fatal Error] TaskSchDemo.dpr(10): Could not compile used unit 'main.pas'



197      function GetITask(TaskName: string): ITask;
198      var
199        PITask: IUnknown;
200        hr: HRESULT;
201      begin
202        hr := SchedulingAgent.Activate(StrToWide(TaskName), IID_ITask, PITask);
203        if hr = S_OK then Result := ITask(PITask)
204        else
205        begin
206          ShowMessage('Error in SchedulingAgent.Activate.Error Code :' + IntToHex(hr, 8));
207          Result := nil;
208        end;
209
210      end;



890      procedure TfrmMain.btnNewWorkItemClick(Sender: TObject);
890      var
890        HR: HRESULT;
890        TaskName: string;
890        WorkItem: IUnknown;
890      
890      begin
890        TaskName := InputBox('Enter Task Name', 'Name?', '');
890        if TAskName = '' then
890        begin
890          ShowMessage('You have to enter a task name');
890          exit;
890        end;
890        Init;
890        HR := SchedulingAgent.NewWorkItem(StrToWide(TaskName), CLSID_CTask,
890          IID_IScheduledWorkItem, WorkItem);
890        Task := ITask(WorkItem); //required for save
890        ScheduledWorkItem := IScheduledWorkItem(WorkItem);
890        if HR = S_OK then StatusMemo.Lines.Add(Taskname + ' created successfully')
890        else
890        begin
890          StatusMemo.Lines.Add('Could not create the job ' + taskname + ' Error Code :' + IntTohex(hr, 8));
890          exit;
890        end;
890        hr := SaveTAsk;
890        if hr <> S_OK then StatusMemo.lines.add('Save task failed with error code' + IntTohex(hr, 8) + #13#10);
890        BtnGetTasksClick(self); //for updating
890      end;
0
Comment
Question by:philippe_beauregard
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 23

Accepted Solution

by:
Ferruccio Accalai earned 500 total points
ID: 9814431
you cannot pass a constant as a variable so change code as follows:

function GetITask(TaskName: string): ITask;
var
  PITask: IUnknown;
  hr: HRESULT;
  MyIid_ITask: TGuid;
begin
  MyIid_ITask := IID_ITask;
  hr := SchedulingAgent.Activate(StrToWide(TaskName),  MyIid_ITask, PITask);
  if hr = S_OK then Result := ITask(PITask)
  else
  begin
    ShowMessage('Error in SchedulingAgent.Activate.Error Code :' + IntToHex(hr, 8));
    Result := nil;
  end;

end;

procedure TfrmMain.btnNewWorkItemClick(Sender: TObject);
var
  HR: HRESULT;
  TaskName: string;
  WorkItem: IUnknown;
  MyCLSID_CTask, MYIID_IScheduledWorkItem: TGuid;
begin
  MyCLSID_CTask := CLSID_CTask;
  MyIID_IScheduledWorkItem := IID_IScheduledWorkItem;
  TaskName := InputBox('Enter Task Name', 'Name?', '');
  if TAskName = '' then
  begin
    ShowMessage('You have to enter a task name');
    exit;
  end;
  Init;
  HR := SchedulingAgent.NewWorkItem(StrToWide(TaskName), MyCLSID_CTask,
    MyIID_IScheduledWorkItem, WorkItem);
  Task := ITask(WorkItem); //required for save
  ScheduledWorkItem := IScheduledWorkItem(WorkItem);
  if HR = S_OK then StatusMemo.Lines.Add(Taskname + ' created successfully')
  else
  begin
    StatusMemo.Lines.Add('Could not create the job ' + taskname + ' Error Code :' + IntTohex(hr, 8));
    exit;
  end;
  hr := SaveTAsk;
  if hr <> S_OK then StatusMemo.lines.add('Save task failed with error code' + IntTohex(hr, 8) + #13#10);
  BtnGetTasksClick(self); //for updating
end;

F68 ;-)

0
 

Author Comment

by:philippe_beauregard
ID: 9814497
Thanks F68,

That's exactly what was needed.

-phil

0
 
LVL 23

Expert Comment

by:Ferruccio Accalai
ID: 9814535
pleased for having helped 'u' :)
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses
Course of the Month10 days, 1 hour left to enroll

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question