Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to use Outlook Automation - Contactlist Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
07-Jul-03
Category
OLE
Language
Delphi 5.x
Views
139
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Vladimir Orlenko

How use Outlook's Contact list in Applications

Answer:

This is sample how look and change information in Outlook's Contactlist from 
external application. 

1   unit Unit1;
2   
3   interface
4   
5   uses
6     Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
7     StdCtrls;
8   const
9     // constants from MSOUTL8.olb
10  
11    olByValue = 1;
12    olByReference = 4;
13    olEmbeddedItem = 5;
14    olOLE = 6;
15  
16    olMailItem = 0;
17    olAppointmentItem = 1;
18    olContactItem = 2;
19    olTaskItem = 3;
20    olJournalItem = 4;
21    olNoteItem = 5;
22    olPostItem = 6;
23  
24    olFolderDeletedItems = 3;
25    olFolderOutbox = 4;
26    olFolderSentMail = 5;
27    olFolderInbox = 6;
28    olFolderCalendar = 9;
29    olFolderContacts = 10;
30    olFolderJournal = 11;
31    olFolderNotes = 12;
32    olFolderTasks = 13;
33  
34  type
35    TForm1 = class(TForm)
36      Label1: TLabel;
37      Label2: TLabel;
38      mName: TMemo;
39      mFamily: TMemo;
40      mFullName: TMemo;
41      mCompany: TMemo;
42      mSaveAs: TMemo;
43      mBody: TMemo;
44      btnSave: TButton;
45      sbContacts: TScrollBar;
46      btnConnect: TButton;
47      procedure btnConnectClick(Sender: TObject);
48      procedure mNameChange(Sender: TObject);
49      procedure sbContactsChange(Sender: TObject);
50      procedure btnSaveClick(Sender: TObject);
51    private
52      { Private declarations }
53      IsDirty: boolean;
54    public
55      { Public declarations }
56      OlApp, Namespace, ContactFolder: OleVariant;
57      procedure LoadContact(I: Integer; folder: OleVariant);
58      procedure SaveContact(I: Integer; folder: OleVariant);
59    end;
60  
61  var
62    Form1: TForm1;
63  
64  implementation
65  uses ComObj;
66  {$R *.DFM}
67  
68  procedure TForm1.btnConnectClick(Sender: TObject);
69  begin
70    OlApp := CreateOleObject('Outlook.Application');
71    Namespace := OlApp.GetNameSpace('MAPI');
72    ContactFolder := Namespace.GetDefaultFolder(olFolderContacts);
73    sbContacts.Max := ContactFolder.Items.Count;
74    sbContacts.Position := 1;
75    LoadContact(1, ContactFolder);
76  end;
77  
78  procedure TForm1.LoadContact(I: Integer; folder: OleVariant);
79  var
80    Item: OleVariant;
81  begin
82    Caption := 'Rec ' + IntToStr(i) + ' from ' + IntToStr(sbContacts.Max);
83    Item := folder.Items(I);
84    mName.Text := Item.FirstName;
85    mFamily.Text := Item.LastName;
86    mFullName.Text := Item.FullName;
87    mCompany.Text := Item.CompanyName;
88    mSaveAs.Text := Item.FileAs;
89    mBody.Text := Item.Body;
90  end;
91  
92  procedure TForm1.SaveContact(I: Integer; folder: OleVariant);
93  var
94    Item: OleVariant;
95  begin
96    Item := folder.Items(I);
97    Item.FirstName := mName.Text;
98    Item.LastName := mFamily.Text;
99    Item.FullName := mFullName.Text;
100   Item.CompanyName := mCompany.Text;
101   Item.FileAs := mSaveAs.Text;
102   Item.Body := mBody.Text;
103   Item.Save;
104   isDirty := False;
105 end;
106 
107 procedure TForm1.mNameChange(Sender: TObject);
108 begin
109   IsDirty := True;
110 end;
111 
112 procedure TForm1.sbContactsChange(Sender: TObject);
113 begin
114   LoadContact(sbContacts.Position, ContactFolder);
115 end;
116 
117 procedure TForm1.btnSaveClick(Sender: TObject);
118 begin
119   SaveContact(sbContacts.Position, ContactFolder);
120 end;
121 
122 end.


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC