Einzelnen Beitrag anzeigen

mc-bain

Registriert seit: 11. Jan 2010
14 Beiträge
 
#1

Outlook Kalender Items finden und löschen

  Alt 1. Aug 2014, 16:23
Hallo
ich möchte ein Programm für Outlook schreiben.
Ich kann bereits Termine im Kalender anlegen:
Code:
var
  outlook, ns, folder, appointment, prop: OLEVariant;
  const olFolderCalendar = $00000009;
         olText = 1;
begin
  {initialize an Outlook}
  outlook := CreateOLEObject('Outlook.Application');
  {get MAPI namespace}
  ns := outlook.GetNamespace('MAPI');
  {get a default Contacts folder}
  folder := ns.GetDefaultFolder(olFolderCalendar);
  {if Contacts folder is found}
  if not VarIsNull(folder) then
  begin
    try
      appointment := folder.Items.Find('[GC-ID]=''1004''');
     
    except
    end;

    if varType(Appointment)=varNull) or
      (varType(Appointment)=varEmpty) then
    begin
      showMessage('NEW');
      {create a new item}
      appointment := folder.Items.Add(olAppointmentItem);
      prop := appointment.UserProperties.Add('GC-ID',olText,True);
      prop.Value := '''1004''';

      {define a subject and body of appointment}
      appointment.Subject := 'new appointment';
      appointment.Body := 'call me tomorrow';

      {duration: 10 days starting from today}
      appointment.Start := Now();
      appointment.End := Now()+10; {10 days for execution}
      appointment.AllDayEvent := 1; {all day event}

      {set reminder in 20 minutes}
      appointment.ReminderMinutesBeforeStart := 20;
      appointment.ReminderSet := 1;

      {set a high priority}
      appointment.Importance := olImportanceHigh;

      {to save an appointment}
      appointment.Save;
Ich gebe also meinen neuen Termin eine individuelles Attribut GC-ID=1004.
Nun möchte ich genau diesen Termin später löschen. Hierfür verwende ich folgenden Code:


Code:
var
  outlook, ns, folder, appointment, prop: OLEVariant;
  const olFolderCalendar = $00000009;
         olText = 1;
begin
  {initialize an Outlook}
  outlook := CreateOLEObject('Outlook.Application');
  {get MAPI namespace}
  ns := outlook.GetNamespace('MAPI');
  {get a default Contacts folder}
  folder := ns.GetDefaultFolder(olFolderCalendar);
  {if Contacts folder is found}
  if not VarIsNull(folder) then
  begin
    try
      appointment := folder.Items.Find('[GC-ID]=''1004''');
     
    except
    end;

    if not (varType(Appointment)=varNull) or not (varType(Appointment)=varEmpty) then
    begin
       appointment.Delete;
    end;
Das funktioniert auch. Allerdings findet mir die Find Methode - wenn ich nun wieder nach GC-ID=1004 suche - immer noch den Termin, obwohl ich ihn gelöscht habe.
Hat jemand evtl. einen Tip für mich, wie ich einen Termin aus dem Kalender endgültig entfernen kann, damit er auch nicht mehr über Find gefunden wird?

Vielen DAnk.
Viele Grüße
mc
  Mit Zitat antworten Zitat