Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Sonstige Fragen zu Delphi (https://www.delphipraxis.net/19-sonstige-fragen-zu-delphi/)
-   -   Delphi Outlook: Prüfen, ob Kontakt Mailadresse hat (https://www.delphipraxis.net/87045-outlook-pruefen-ob-kontakt-mailadresse-hat.html)

FBrust 22. Feb 2007 14:24


Outlook: Prüfen, ob Kontakt Mailadresse hat
 
Hallo,

ich möchte in meinem Programm die Kontakte (Namen und Mailadressen) aus Outlook auslesen und in einem Grid darstellen.

Allerdings möchte ich nur die Kontakte darstellen, die eine Mailadresse haben. Wenn ich allerdings mit

Delphi-Quellcode:
    outlook := CreateOleObject('Outlook.Application');
    NameSpace := outlook.GetNameSpace('MAPI');

    Contacts := NameSpace.GetDefaultFolder(olFolderContacts);
    for i := 1 to Contacts.Items.Count do begin
      if Contact.Email1Address = '' then
        showmessage('keine Adresse');
....
prüfe, erhalte ich die Meldung "Ungültige Variant-Operation" bei "if Contact.Email1Adress = ''". Die Prüfung auf Length = 0 bringt den gleichen Fehler.. :?:

Wie kann ich denn feststellen, ob im Feld "Email1Adress" von Outlook etwas eingetragen ist?


Gruß
Frank

ste_ett 22. Feb 2007 15:28

Re: Outlook: Prüfen, ob Kontakt Mailadresse hat
 
In deinem Code taucht auf einmal "Contact" auf. :)

Hast du das gesetzt?

Delphi-Quellcode:
Contact := Contacts.Items[i];
Der zweite Punkte ist, dass Outlook dir in dem Array der Kontakte nicht nur einzelne Kontakte, sondern auch Gruppen von Kontakten zurückgibt.
Dieses Objekt hat dieEigenschaft "Email1Address" nicht.
Du musst zuerst prüfen, ob das Objekt, was du zurück bekommen hast auch wirklich ein Kontakt ist. :)

Delphi-Quellcode:
const
// Folders
  olFolderContacts    = 10;

// Classes
  olContact = 40;
  olDistributionList = 69;

procedure TForm1.Button1Click(Sender: TObject);
var
  Outlook, NameSpace, Contacts, Contact: OleVariant;
  i, c: Integer;
  s, ItemClass: String;
begin
  Outlook := CreateOleObject('Outlook.Application');
  try
    NameSpace := outlook.GetNameSpace('MAPI');
    try
      Contacts := NameSpace.GetDefaultFolder(olFolderContacts);
      try
        c := Contacts.Items.Count;
        for i := 1 to c do
        begin
          ItemClass := Contacts.Items[i].Class;

          if (StrToIntDef(ItemClass, -1) = olContact) then
          begin
            Contact := Contacts.Items[i];        
            s := Contact.Email1Address;

// dein Code *******************************************************************
           if (Length(s) = 0) then
              ShowMessage('Keine Adresse!');

//******************************************************************************             
          end;
        end;
      finally
        Contacts := Unassigned;
      end;
    finally
      NameSpace := Unassigned;
    end;
  finally
    Outlook := Unassigned;
  end;
end;
- edit -

olDistributionList/69 ist eine Gruppe von Benutzern.

FBrust 22. Feb 2007 15:32

Re: Outlook: Prüfen, ob Kontakt Mailadresse hat
 
Hallo Stefan,

danke für Deine Antwort.

Ja, "contacts" hab ich gesetzt, aber das mit den Gruppen war mir neu, werds mal ausprobieren.


Gruß
Frank

Nachtrag: Hat super funktioniert, danke! :thumb:


Alle Zeitangaben in WEZ +1. Es ist jetzt 05:08 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