Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Sonstige Fragen zu Delphi (https://www.delphipraxis.net/19-sonstige-fragen-zu-delphi/)
-   -   Outlook, OLE, Outlook.Exe wird nicht beendet (https://www.delphipraxis.net/169495-outlook-ole-outlook-exe-wird-nicht-beendet.html)

hoika 24. Jul 2012 10:07

Outlook, OLE, Outlook.Exe wird nicht beendet
 
Hallo #,

folgender Code klappt soweit ganz gut.
Leider bleibt aber die Outlook.Exe (Outlook 2007) offen.
Warum ?

Danke


Heiko

Delphi-Quellcode:
var

uses
  OutlookXP;
var
  Outlook: OutlookXP._Application; // OutlookApplication; for D5 users
  NmSpace: NameSpace;
  Folder: MAPIFolder;
  Inbox: MAPIFolder;
  InboxSubFolder: MAPIFolder;
  bFound: Boolean;
begin
  Outlook := CoOutlookApplication.Create;

  NmSpace := Outlook.GetNamespace('MAPI');
  NmSpace.Logon('', '', False, False);

  Inbox:= NmSpace.GetDefaultFolder(olFolderInbox);
//  MessageBox(0, PChar(IntToStr(Inbox.Items.Count)), 'Inbox', 0);

  bFound:= False;
  for i := 1 to Inbox.Folders.Count do
  begin
    InboxSubFolder:= Inbox.Folders.Item(i);
    sSubFolderName:= InboxSubFolder.Name;
    if sSubFolderName='MySubFolder'{heisst anders} then
    begin
      bFound:= True;
      break;
    end;
  end;


    Inbox:= NIL;
    InboxSubFolder:= NIL;
    NmSpace.Logoff;
    Outlook.Quit;
    Outlook := nil;       // Early binding with interfaces
  end;

RWarnecke 24. Jul 2012 10:19

AW: Outlook, OLE, Outlook.Exe wird nicht beendet
 
Probier mal
Delphi-Quellcode:
Outlook := UnAssigned
, bei Excel funktioniert es auf jedenfall.

hoika 24. Jul 2012 11:55

AW: Outlook, OLE, Outlook.Exe wird nicht beendet
 
Hallo,

hat sich erledigt.
UnAssigned klappt hier nicth, weil es kein Variant ist.

Lösung.

Da es sich um Interfaces handelt,
muss die Methode, die das Interface benutzt, beendet werden.
Ich hatte clevererweise ein MessageBox drin ;)


Heiko

himitsu 24. Jul 2012 12:13

AW: Outlook, OLE, Outlook.Exe wird nicht beendet
 
Du nutzt implizite Variablen und bei Interfaces/Strings/Arrays/Variants werden auch erst spätestens im "end;" freigegeben.
Ausahme: Wenn sie innerhalb von Schleifen wiederverwendet werden, aber auch da geht die letzte Instanz ebenfalls erst am Ende der Prozedur von Dannen.

z.B.
Delphi-Quellcode:
Inbox.Folders.xxx
... Folders ist doch bestimmt auch ein Interface? Delphi muß diese Instanz ja irgendwo speichern, also legt es sich selber eine lokale Variable an.

Entweder du beendest eben die ganze Prozedur/Methode oder du verwaltest alle Variablen selber.


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