Navigation Menu Search PhysiologyWeb
PhysiologyWeb Logo Search PhysiologyWeb
   
— share —
Share on Facebook    Share on X    Share on LinkedIn    Share on Pinterest    Share on Reddit    Email    Copy URL
procedure TForm1.UseDelphiToCreateMicrosoftOutlookTask(Sender: TObject);
var
OutlookApplication, OutlookTaskItem: Variant;
begin
//be sure ComObj and Variants units are included in the "uses" clause

OutlookApplication := Null;
OutlookTaskItem := Null;

try
//create Outlook OLE
OutlookApplication := CreateOleObject('Outlook.Application');
except
OutlookApplication := Null;
//add error/exception handling code as desired
end;

If VarIsNull(OutlookApplication) = False then
begin
try
//Create Outlook Task Item
try
OutlookTaskItem := OutlookApplication.CreateItem(3); //olTaskItem = $00000003
//reference
//https://docs.microsoft.com/en-us/office/vba/api/outlook.taskitem
except
OutlookTaskItem := Null;
//add error/exception handling code as desired
end;

If VarIsNull(OutlookTaskItem) = False then
begin
OutlookTaskItem.Categories := 'New Task Category'; //use a predefined category or create a new category
OutlookTaskItem.Subject := 'Outlook Task Item';
OutlookTaskItem.Body := 'This Microsoft Outlook task was created programmatically by Delphi!';
OutlookTaskItem.StartDate := EncodeDateTime(2022, 9, 5, 8, 0, 0, 0);
OutlookTaskItem.DueDate := EncodeDateTime(2022, 9, 9, 17, 0, 0, 0);
OutlookTaskItem.ReminderSet := True;
OutlookTaskItem.ReminderTime := EncodeDateTime(2022, 9, 7, 8, 0, 0, 0);
OutlookTaskItem.Status := 0; //OlTaskStatus enumeration: 0 = not started, 1 = in progress, 2 = complete, 3 = waiting, 4 = deferred
OutlookTaskItem.Importance := 1; //OlImportance enumeration: 0 = low, 1 = normal, 2 = high
OutlookTaskItem.Save;
//reference
//https://docs.microsoft.com/en-us/office/vba/api/outlook.taskitem
//note: the time component of StartDate and DueDate is set to zero
//note: ReminderTime has both date and time components
end;
finally
OutlookTaskItem := Unassigned;
OutlookApplication := Unassigned;
end;
end;
end;




Posted: Sunday, August 28, 2022
Last updated: Tuesday, March 18, 2025
— share —
Share on Facebook    Share on X    Share on LinkedIn    Share on Pinterest    Share on Reddit    Email    Copy URL