Find Deleted Meeting in Outlook by Delphi

I am trying to integrate our program with Outlook and my test code below (sort of works) but has the following problems.

During testing, I was able to add an appointment. Then manually moved the appointment to a different date / time and restarted the test program and it came back (as expected). But...

when the item is removed, the code below can still find the item (somehow!). I even manually deleted the item from the Deleted Items folder in Outlook.

as a result, since it "found" the destination, it then tries to update it, resulting in an AV. I suspect there is something wrong with my use of the find function, but I am trying to use userProperties to add something from our system to add a destination item to Outlook and update if needed. But you also need to be able to handle the case where the user can manually remove an item from the calendar.

Any help would be greatly appreciated.

folder := ns.GetDefaultFolder(olFolderCalendar);

if not VarIsNull(folder) and not VarIsEmpty(folder) then
begin
try
  appointment := folder.Items.Find('[MyRecProperty2]=' + quotedStr(1001));
  entryFound := true;
except
end;

if (not entryFound) or
  (varType(Appointment)=varNull) or
  (varType(Appointment)=varEmpty) then
begin
  appointment := folder.Items.Add(olAppointmentItem);
  prop := appointment.UserProperties.Add('MyRecProperty2',olText,True);
  prop.Value := '1001';
  NewAppointment(appointment);
end
else
begin
  showmessage('updating appointment!');
  FillAppointment(appointment, false);
end;

showmessage('saving appointment!');
appointment.Save;

//showmessage('display appointment!');
//appointment.Display(true);

      

+3


source to share





All Articles