Autor Beitrag
56K-Surfer
ontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic star
Beiträge: 26



BeitragVerfasst: Mi 04.05.05 19:20 
Hallo Leute

Ich versuche mit einem Delphiprogramm die Termine aus Outlook auszulesen. Im nachfolgenden Codeschnipsel ist mein augenblicklicher Stand zu sehen. Ich hab mir schon viel aus dem Netz zusammengesucht und soweit ich das verstehe müsste das jetzt funktionieren.
Tut es aber nicht. Delphi hängt sich bei der markierten Zeile hiermit auf:

... class EOleSysError with message "unbekannter Fehler" ...

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
uses ..., COMOBJ;

...

procedure TForm1.Button1Click(Sender: TObject);
const
  olAppointmentItem = $00000001;

  olImportanceLow = 0;
  olImportanceNormal = 1;
  olImportanceHigh = 2;

  {to find a default Contacts folder}
  function GetCalendarFolder(folder: OLEVariant): OLEVariant;
  var
    i: Integer;
  begin
    for i := 1 to folder.Count do
    begin
      if (folder.Item[i].DefaultItemType = olAppointmentItem) then
        Result := folder.Item[i]
      else
        Result := GetCalendarFolder(folder.Item[i].Folders);
      if not VarIsNull(Result) and not VarIsEmpty(Result) then
        break
    end;
  end;

var
  outlook, ns, folder: OLEVariant;
  i: integer;
  s: String;
begin
  {initialize an Outlook}
  outlook := CreateOLEObject('Outlook.Application');
  {get MAPI namespace}
  ns := outlook.GetNamespace('MAPI');
  {get a default Contacts folder}
  folder := GetCalendarFolder(ns.Folders);
  {if Contacts folder is found}
  if not VarIsNull(folder) and not VarIsEmpty(folder) then
  begin
    For i := 1 to folder.items.count do
    begin
      s := folder.items[i].Subject; //##################### HIER HÄNGT DELPHI SICH AUF
      listbox1.Items.Add(s);
    end;
  end;

  {to free all used resources}
  folder := UnAssigned;
  ns := UnAssigned;
  outlook := UnAssigned
end;


Hat jemand eine Idee was ich da falsch gemacht haben könnte?

_________________
Ich liebe meinen iPod...


Zuletzt bearbeitet von 56K-Surfer am Do 05.05.05 11:49, insgesamt 2-mal bearbeitet
wulfskin
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1349
Erhaltene Danke: 1

Win XP
D5 Pers (SSL), D2005 Pro, C, C#
BeitragVerfasst: Mi 04.05.05 20:04 
Sollte es nicht so heissen:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
    For i := 0 to folder.items.count - 1 do
    begin
      s := folder.items[i].Subject; //##################### HIER HÄNGT DELPHI SICH AUF
      listbox1.Items.Add(s);
    end;
?

Gruß Hape!

_________________
Manche antworten um ihren Beitragszähler zu erhöhen, andere um zu Helfen.
56K-Surfer Threadstarter
ontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic star
Beiträge: 26



BeitragVerfasst: Do 05.05.05 11:13 
Danke für die schnelle Antwort.

Ne das funktioniert leider auch nicht. Ich hatte auch wo gelesen das der Index bei den OLE-Zugriffen bei 1 startet.
Wenn der Index bei 0 startet kommt eine Meldung das der Array-index außerhalb des gültigen Bereiches ist.

Trotzdem danke. :D

_________________
Ich liebe meinen iPod...
Robert.Wachtel
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 895
Erhaltene Danke: 7

Windows 7 Ultimate x64
D5 Ent, D7 Arch, RAD Studio 2010 Pro, VS 2008
BeitragVerfasst: Do 05.05.05 11:34 
user profile icon56K-Surfer hat folgendes geschrieben:
[Problem mit Outlook-Zugriff]
Das möchtest Du jetzt bestimmt nicht hören, aber Dein Quelltext läuft hier (Delphi 7) einwandfrei.
56K-Surfer Threadstarter
ontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic star
Beiträge: 26



BeitragVerfasst: Do 05.05.05 11:47 
Buhuhuhu..... :crying: Richtig! Das wollte ich eigentlich garnicht hören.
Naja, immerhin ist der Code richtig. Ich hab aber auch D7 und Office 2003. :gruebel:

_________________
Ich liebe meinen iPod...
56K-Surfer Threadstarter
ontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic star
Beiträge: 26



BeitragVerfasst: Do 05.05.05 12:12 
Grrrrr.... :autsch:

Ich hab noch ein bissl getüftelt und nun die betroffene Codezeile in ein Try...Except-Block gepackt. Wenn des Programm in der Delphi IDE läuft kommt der Fehler immer noch. Wenn es aber Standalone läuft funktioniert es. Da muss man erstmal drauf kommen...

Was ich komisch finde ist das keine Sicherheitsabfrage von Office kommt. Ich hatte mal gehört das Office sich eine Sicherheitswarnung ausgibt wenn ein externes Programm auf die Daten zugreifen will? Naja, um so besser.

Wie dem auch sei. Vielen Dank für eure Hilfe :flehan:

ciao

_________________
Ich liebe meinen iPod...