Dismiss Notice

REGISTRATION IS AFTER ADMIN ACTIVATION

DONATIONS WITH PAYPAL CLICK TO BUTTON

6 MONTHS VIP - 20$; 1 YEAR VIP - 30$; 2 YEARS VIP - 50$; GOLD USER FOR LIFE VIP - 150$

DONATIONS WITH Bitcoin Address:3NRs3CK3fhXifrNYxHEZKpETDd9vNLMsMD

Dismiss Notice
The registration is approved by the Administrator. It takes about 1 day to approve your registration
Dismiss Notice
For open hidden message no need write thanks, thank etc. Enough is click to like button on right side of thread.

Outlook from Delphi

Discussion in 'Delphi Programming' started by AdminDF, Feb 1, 2014.

  1. AdminDF
    Online

    AdminDFAdminDF is a Verified Member DelphiFan Administrator Staff Member DF Staff

    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]Problem/Question/Abstract:[/font]

    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]Outlook from Delphi[/font]

    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]Answer:[/font]

    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]Automating Microsoft Outlook [/font]

    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]Microsoft Office 97 appears to be five well-integrated applications. It is, in fact, much more. Office 97 was created using Microsoft's Component Object Model (COM). The Office applications are composed of a series of COM servers you can access from your Delphi applications using Automation (formerly know as OLE Automation). Beginning with Outlook 98, this article series will explore the object model of each of the office applications - and how you can use them from Delphi.[/font]

    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]The Outlook object model consists of objects and collections of objects (see Figure 1). The top-level object in Outlook 98 is the Application object. The Application object is the root of the object tree and provides access to all the other Outlook objects. The Application object is unique in that it's the only object you can gain access to by calling CreateOleObject from a Delphi (or any other) application. Next comes the NameSpace object, which provides access to a data source. The only available data source in Outlook 98 is the MAPI message store.[/font]


    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]Figure 1: The Outlook object model.[/font]

    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]The MAPIFolders collection is just that - a collection of MAPI folders. You can think of collections as arrays of objects, somewhat like a Delphi TList. However, collection objects can be referenced by name or number. The MAPIFolder object in Figure 1 represents one of the folders in the MAPIFolders collection. Each MAPIFolder contains a Folders collection, and each of these contains an Items collection that contains the items appropriate to that folder. For example, the Contacts folder contains contact items.[/font]

    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]Figure 2 shows the main form of a Delphi project that displays the MAPIFolders collection, the Folders collection of the MAPI Personal folder, and the Items in the Contacts folder. Listing One  displays the code from the Open Outlook button's OnClick event handler.[/font]


    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]Figure 2: The MAPI Folders collection displayed in a Delphi form.[/font]

    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]The code in Listing One begins by declaring four Variant variables for use as references to various Outlook objects. The call to CreateOleObject loads the Outlook server and returns a reference to the Application object. The parameter passed to CreateOleObject, Outlook.Application, is the class name Outlook registers itself as when it's installed. Using the Application object you can get a reference to any other Outlook object.[/font]

    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]Calling the Application object's GetNameSpace method returns a reference to the NameSpace passed as a parameter. Using the MAPI NameSpace reference variable, Mapi, the code loops through the MAPIFolders collection and adds the name of each folder to the MapiList listbox. As with all objects in object-oriented programming, Outlook objects have properties, methods, and events. The Count property of the Folders collection is used to limit the number of times the for loop executes. All collections have a Count property to provide the number of objects in the collection. Each Folder in the MAPIFolders collection also has a Name property.[/font]

    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]As you can see in Figure 2, the MAPIFolders collection contains two folders, Microsoft Mail Shared Folders and Personal Folders. The following statement gets a reference to the Personal Folders collection from the MAPIFolders collection. While the for loop that displayed the names of the MAPI Folders accessed the MAPIFolders collection by number, the statement:[/font]

    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]Personal := Mapi.Folders('Personal Folders');[/font]

    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]indexes the collection by name. The next for loop uses the reference to the Personal Folder to display the names of all the folders in its Folders collection in the second listbox in Figure 2. The code then gets a reference to the Contacts folder and uses it to loop through the Contacts folder's Items collection. One of the properties of a Contact item is FullName; this property is added to the third listbox to display the names of the contacts.[/font]

    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]Clearly, the secret to working with Outlook 98 from your Delphi applications is understanding the Outlook object hierarchy and the properties, methods, and events of each object. Outlook 97 includes a Help file, VBAOUTL.HLP, that contains this information; however, I have been unable to find it on the Outlook 98 CD. Fortunately, very little has changed in Outlook 98. (Outlook 2000 is a different story, and will be the topic of a future article.) [/font]

    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]Working with Contacts[/font]

    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]Listing Two  shows the OnClick event handler from the LoadTbl project that accompanies this article. This code demonstrates how to search the Outlook Contacts folder for the records you wish to select and copy them to a database table.[/font]

    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]As in the example shown in Listing One, this one begins by getting the Application object and the MAPI NameSpace object. Next, a reference is obtained using the statement:[/font]

    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]ContactItems := Mapi.Folders('Personal Folders').[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]Folders('Contacts').Items;[/font]

    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]This statement demonstrates how you can chain objects together using dot notation to get a reference to a low-level object without having to get individual references to each of the higher level objects. In this case, five levels of intervening objects are specified to get to the Items object of the Contacts folder. These objects are:[/font]

    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]The MAPI NameSpace object [/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]The Folders collection [/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]The Personal Folders object [/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]The Folders collection [/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]The Contacts object [/font]

    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]You can use this notation to get a reference to any Outlook object in a single statement. The next new feature of this method is the call to the Find method of the ContactItems collection. Almost all collection objects have a Find method you can use to locate a particular item in the collection using one or more of its properties. In this example, the statement:[/font]

    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]CurrentContact := ContactItems.Find(' [CompanyName] = ' +[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]  QuotedStr('Borland International'));[/font]

    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]finds the first contact item where the value of the CompanyName property is equal to Borland International. If no matching item is found, the Variant CurrentContact will be empty. The while loop inserts a new record into the database table, and assigns each of the Contact item's properties to the corresponding field in the table. The while loop continues until CurrentContact is empty, indicating that no more items matching the search criteria can be found. At the end of the while loop, the call to FindNext finds the next matching record, if there is one. If no record is found, CurrentContact is set to empty and the loop terminates.[/font]

    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]Creating new Contact folders and records is just as easy. Suppose you want to copy all your Contact records for Borland employees into a new folder. The code in Listing Three  from the NewFolder sample project will do the job.[/font]

    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]This method begins by getting the Application, MAPI NameSpace, and Contacts folder's Items object. Next, it uses a for loop to scan the Folders collection looking for the Borland Contacts folder. If the folder is found, its number is assigned to the ToRemove variable. The Borland Contacts folder is deleted by calling the Folders collection's Remove method and passing the ToRemove variable as the parameter.[/font]

    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]Next, a call to the Folders collection's Add method creates the Borland Contacts folder. Add takes two parameters. The first is the name of the folder to be created. The second parameter is the folder type and can be olFolderCalendar, olFolderContacts, olFolderInbox, olFolderJournal, olFolderNotes, or olFolderTasks. To find the values of these and any other constants you need, search the VBAOUTL.HLP file for Microsoft Outlook Constants. The next statement gets a reference to the new Borland Contacts folder and stores it in the BorlandContacts variable.[/font]

    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]A call to the Contacts folder's Items collection's Find method locates the first record for a Borland employee. The while loop is used to iterate through all the Borland employees in the Contacts folder. At the top of the loop a new record is added to the Borland Contacts folder by calling the folder's Items collection's Add method.[/font]

    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]Add takes no parameters; it simply inserts a new empty record and returns a reference to the new record, which is saved in the NewContact variable. The statements that follow assign values from the existing record to the new one. Finally, the new record's Save method is called. This is a critical step. If you don't call Save, no errors will be generated - but there will be no new records in the folder. When the while loop terminates Outlook is closed by assigning the constant Unassigned to the OutlookApp variable.[/font]

    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]Other Outlook Objects[/font]

    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]The Folders collection of the Personal Folder object contains the following folders:[/font]

    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]Deleted Items [/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]Inbox [/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]Outbox [/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]Sent Items [/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]Calendar [/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]Contacts [/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]Journal [/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]Notes [/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]Tasks [/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]Drafts [/font]

    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]You can work with the Items collection of any of these folders using the same code shown for working with Contacts. Only the properties of the items are different. Listing Four  shows a method that copies to a Paradox table all appointments that are all-day events and whose start date is greater than 4/27/99. This example copies the Start, End, Subject and BusyStatus properties to the table. Note that this example uses a more sophisticated find expression than previous examples. Find supports the >, <, >=, <=, = and <> operators, as well as the logical operators and, or, and not, which allows you to construct complex search expressions.[/font]

    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]Conclusion[/font]

    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]Delphi applications can easily act as Automation clients, allowing your applications to interact with the Microsoft Office Suite applications in any way you wish. Using Outlook you can extract contact information to update a central database, add new contacts derived from other sources, create new folders, and add items of any type. One of Outlook's limitations is its lack of a powerful reporting tool. With a Delphi application you can provide much more powerful reporting capabilities for Outlook data. With a basic understanding of the Outlook object model and a copy of the VBAOUTL.HLP help file you are well on your way.[/font]


    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]Begin Listing One - Displaying Outlook objects[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]procedure TForm1.OpenBtnClick(Sender: TObject);[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]var[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]  OutlookApp,[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]    Mapi,[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]    Contacts,[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]    Personal: Variant;[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]  I: Integer;[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]begin[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]  { Get the Outlook Application object. }[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]  OutlookApp := CreateOleObject('Outlook.Application');[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]  { Get the MAPI NameSpace object. }[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]  Mapi := OutlookApp.GetNameSpace('MAPI');[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]  { Loop through the MAPI Folders collection and add the[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]   Name of each folder to the listbox. }[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]  for I := 1 to Mapi.Folders.Count do[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]    MapiList.Items.Add(Mapi.Folders(I).Name);[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]  { Get the Personal folder from the MAPI folders[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]   collection. }[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]  Personal := Mapi.Folders('Personal Folders');[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]  { Loop through the Personal Folders Collection and add[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]   the name of each folder to the listbox. }[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]  for I := 1 to Personal.Folders.Count do[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]    PersonalList.Items.Add(Personal.Folders(I).Name);[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]  { Get the Contacts folder from the Personal Folders[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]   collection. }[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]  Contacts := Personal.Folders('Contacts');[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]  { Loop through the Contacts folder's Items collection[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]   and add the FullName property of each Item[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]   to the listbox. }[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]  for I := 1 to Contacts.Items.Count do[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]    ContactsList.Items.Add(Contacts.Items(I).FullName);[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]  { Close Outlook. }[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]  OutlookApp := Unassigned;[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]end;[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]End Listing One[/font]

    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]Begin Listing Two - Searching for contacts[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]procedure TLoadTableForm.LoadBtnClick(Sender: TObject);[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]var[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]  OutlookApp,[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]    Mapi,[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]    ContactItems,[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]    CurrentContact: Variant;[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]begin[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]  { Get the Outlook Application object. }[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]  OutlookApp := CreateOleObject('Outlook.Application');[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]  { Get the MAPI NameSpace object. }[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]  Mapi := OutlookApp.GetNameSpace('MAPI');[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]  { Get the Items collection from the Contacts folder. If[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]   you don't do this, FindNext will not work. }[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]  ContactItems := Mapi.Folders('Personal Folders').[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]    Folders('Contacts').Items;[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]  { Load Contacts into table. }[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]  with ContactTable do[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]  begin[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]    EmptyTable;[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]    Open;[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]    DisableControls;[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]    CurrentContact :=[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]      ContactItems.Find('[CompanyName] = ' +[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]      QuotedStr('Borland International'));[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]    while not VarIsEmpty(CurrentContact) do[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]    begin[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]      Insert;[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]      FieldByName('EntryId').AsString :=[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]        CurrentContact.EntryId;[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]      FieldByName('LastName').AsString :=[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]        CurrentContact.LastName;[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]      FieldByName('FirstName').AsString :=[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]        CurrentContact.FirstName;[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]      FieldByName('CompanyName').AsString :=[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]        CurrentContact.CompanyName;[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]      FieldByName('BusAddrStreet').AsString :=[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]        CurrentContact.BusinessAddressStreet;[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]      FieldByName('BusAddrPOBox').AsString :=[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]        CurrentContact.BusinessAddressPostOfficeBox;[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]      FieldByName('BusAddrCity').AsString :=[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]        CurrentContact.BusinessAddressCity;[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]      FieldByName('BusAddrState').AsString :=[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]        CurrentContact.BusinessAddressState;[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]      FieldByName('BusAddrPostalCode').AsString :=[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]        CurrentContact.BusinessAddressPostalCode;[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]      FieldByName('BusinessPhone').AsString :=[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]        CurrentContact.BusinessTelephoneNumber;[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]      Post;[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]      CurrentContact := ContactItems.FindNext;[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]    end; // while[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]    EnableControls;[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]  end; // with[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]  { Close Outlook. }[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]  OutlookApp := Unassigned;[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]end;[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]End Listing Two[/font]

    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]Begin Listing Three - Creating a Contacts folder and new contacts[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]procedure TCreateFolderFrom.CreateBtnClick(Sender: TObject);[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]const[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]  olFolderContacts = 10;[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]  olContactItem = 2;[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]var[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]  OutlookApp,[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]    Mapi,[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]    NewContact,[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]    BorlandContacts,[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]    ContactItems,[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]    CurrentContact: Variant;[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]  I,[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]    ToRemove: Integer;[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]begin[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]  { Get the Outlook Application object. }[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]  OutlookApp := CreateOleObject('Outlook.Application');[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]  { Get the MAPI NameSpace object. }[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]  Mapi := OutlookApp.GetNameSpace('MAPI');[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]  { Get the Items collection from the Contacts folder. If[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]   you don't do this,FindNext will not work. }[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]  ContactItems := Mapi.Folders('Personal Folders').[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]    Folders('Contacts').Items;[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]  { Remove the test folder. }[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]  ToRemove := 0;[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]  for I := 1 to Mapi.Folders('Personal Folders').[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]    Folders.Count do[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]    if Mapi.Folders('Personal Folders').Folders(I).Name =[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]      'Borland Contacts' then[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]    begin[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]      ToRemove := I;[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]      Break;[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]    end; // if[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]  if ToRemove <> 0 then[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]    Mapi.Folders('Personal Folders').[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]      Folders.Remove(ToRemove);[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]  { Create a new folder. }[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]  Mapi.Folders('Personal Folders').[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]    Folders.Add('Borland Contacts', olFolderContacts);[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]  BorlandContacts := Mapi.Folders('Personal Folders').[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]    Folders('Borland Contacts');[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]  { Load Contacts into new folder. }[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]  CurrentContact := ContactItems.Find('[CompanyName] = ' +[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]    QuotedStr('Borland International'));[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]  while not VarIsEmpty(CurrentContact) do[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]  begin[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]    { Add a new item to the folder. }[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]    NewContact := BorlandContacts.Items.Add;[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]    { Assign values to the fields in the item record. }[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]    NewContact.FullName := 'John Doe';[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]    NewContact.LastName := CurrentContact.LastName;[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]    NewContact.FirstName := CurrentContact.FirstName;[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]    NewContact.CompanyName := CurrentContact.CompanyName;[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]    NewContact.BusinessAddressStreet :=[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]      CurrentContact.BusinessAddressStreet;[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]    NewContact.BusinessAddressPostOfficeBox :=[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]      CurrentContact.BusinessAddressPostOfficeBox;[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]    NewContact.BusinessAddressCity :=[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]      CurrentContact.BusinessAddressCity;[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]    NewContact.BusinessAddressState :=[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]      CurrentContact.BusinessAddressState;[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]    NewContact.BusinessAddressPostalCode :=[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]      CurrentContact.BusinessAddressPostalCode;[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]    NewContact.BusinessTelephoneNumber :=[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]      CurrentContact.BusinessTelephoneNumber;[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]    { Save the new record. }[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]    NewContact.Save;[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]    { Find the next record in the Contacts folder. }[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]    CurrentContact := ContactItems.FindNext;[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]  end; // while[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]  { Close Outlook. }[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]  OutlookApp := Unassigned;[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]end;[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]End Listing Three[/font]

    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]Begin Listing Four - Reading Calendar folder[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]procedure TLoadTableForm.LoadBtnClick(Sender: TObject);[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]var[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]  OutlookApp,[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]    Mapi,[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]    ApptItems,[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]    CurrentAppt: Variant;[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]begin[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]  { Get the Outlook Application object. }[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]  OutlookApp := CreateOleObject('Outlook.Application');[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]  { Get the MAPI NameSpace object. }[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]  Mapi := OutlookApp.GetNameSpace('MAPI');[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]  { Get the Items collection from the Contacts folder. If[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]   you don't do this, FindNext will not work. }[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]  ApptItems := Mapi.Folders('Personal Folders').[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]    Folders('Calendar').Items;[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]  { Load Contacts into table. }[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]  with ApptTable do[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]  begin[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]    EmptyTable;[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]    Open;[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]    DisableControls;[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]    CurrentAppt := ApptItems.Find('[Start] > ' +[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]      '"4/27/99" and [AllDayEvent] = True');[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]    while not VarIsEmpty(CurrentAppt) do[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]    begin[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]      Insert;[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]      FieldByName('Start').AsDateTime := CurrentAppt.Start;[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]      FieldByName('Subject').AsString :=[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]        CurrentAppt.Subject;[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]      FieldByName('End').AsDateTime := CurrentAppt.End;[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]      FieldByName('Busy').AsBoolean :=[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]        CurrentAppt.BusyStatus;[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]      Post;[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]      CurrentAppt := ApptItems.FindNext;[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]    end; // while[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]    EnableControls;[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]  end; // with[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]  { Close Outlook. }[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]  OutlookApp := Unassigned;[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]end;[/font]
    [font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]End Listing Four[/font]
     
    Pepe likes this.

Share This Page

Laws
Our website, law, laws, copyright and aims to be respectful of individual rights. Our site, as defined in the law of 5651 serves as a provider of space. According to the law, contrary to the law of site management has no obligation to monitor content. Therefore, our site has adopted the principle of fit and remove. Works are subject to copyright laws and is shared in a manner that violated their legal rights, or professional associations, rights holders who, adsdelphi@gmail.com I can reach us at e-mail address. Complaints considered to be infringing on the examination of the content will be removed from our site.
Donate Help To Us and Be VIP
DONATIONS WITH PAYPAL CLICK TO BUTTON
6 MONTHS VIP - 20$; 1 YEAR VIP - 30$; 2 YEARS VIP - 50$; GOLD USER FOR LIFE VIP - 150$
Social Block