Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Win32/Win64 API (native code) (https://www.delphipraxis.net/17-win32-win64-api-native-code/)
-   -   Outlook Kalender Items finden und löschen (https://www.delphipraxis.net/181280-outlook-kalender-items-finden-und-loeschen.html)

mc-bain 1. Aug 2014 16:23

Outlook Kalender Items finden und löschen
 
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

mc-bain 6. Aug 2014 08:16

AW: Outlook Kalender Items finden und löschen
 
Hat noch nie jemand die Find-Methode bei der Outlook-Automatisierung verwendet und festgestellt, dass sie auch noch Termine findet, die eigentlich gelöscht wurden?

DSP 10. Aug 2014 15:03

AW: Outlook Kalender Items finden und löschen
 
Bin zwar nicht der OL crack, jedoch sieht es so aus, als ob du den Eintrag im Papierkorb findest. Kannst du da nicht auf den Folder prüfen?

mc-bain 11. Aug 2014 13:34

AW: Outlook Kalender Items finden und löschen
 
Vielen dank.
Das dachte ich auch zuerst.Allerdings findet Outlook immer noch etwas, auch wenn ich manuell die Email zuvor aus dem Papierkorb gelöscht habe...


Alle Zeitangaben in WEZ +1. Es ist jetzt 14:56 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz