home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 2002 November
/
Chip_2002-11_cd1.bin
/
zkuste
/
delphi
/
kompon
/
d3456
/
OUTLTB.ZIP
/
OutLookTools.pas
next >
Wrap
Pascal/Delphi Source File
|
2002-08-26
|
11KB
|
427 lines
unit OutLookTools;
interface
uses
Windows, Classes, ComCtrls, SysUtils, Dialogs,
ComObj,Graphics, Controls, Forms, Variants;
{*******************************************************************************
* *
* Outlook Connect, Version 1.3 *
*------------------------------------------------------------------------------*
* by Perr Lothar *
* e-mail: lothar.perr@gmx.net *
* *
*******************************************************************************}
const
// OlOutlookBarViewType
olLargeIcon = 0;
olSmallIcon = 1;
// OlDaysOfWeek
olFriday = 32;
olMonday = 2;
olSaturday = 64;
olSunday = 1;
olThursday = 16;
olTuesday = 4;
olWednesday = 8;
//OlSortOrder
olAscending = 1;
olDescending = 2;
olSortNone = 0;
//OlItemType
olAppointmentItem = 1;
olContactItem = 2;
olDistributionListItem = 7;
olJournalItem = 4;
olMailItem = 0;
olNoteItem = 5;
olPostItem = 6;
olTaskItem = 3;
//OlDefaultFolders
olFolderDeletedItems = 3;
olFolderOutbox = 4;
olFolderSentMail = 5;
olFolderInbox = 6;
olFolderCalendar = 9;
olFolderContacts = 10;
olFolderJournal = 11;
olFolderNotes = 12;
olFolderTasks = 13;
olFolderDrafts = 16;
const
msoControlButton = 1;
msoButtonIcon = 1;
msoButtonCaption = 2;
msoButtonIconAndCaption = 3;
type
TCustomEnumWindowsProc = procedure(WinHandle : HWND);
TWindowInfo = class(TObject)
public
Handle : HWND;
end;
TOutlookConnect = class(TComponent)
private
MyOlApp:Variant;
MyNameSpace:Variant;
Active: Boolean;
MyOLEObject:String;
MyOLENameSpace:String;
fOnConnected: TNotifyEvent;
fOnDisConnected: TNotifyEvent;
protected
public
constructor Create(AOwner : TComponent); override;
destructor Destroy; override;
// Global variables
function OutlookApplication: Variant;
function OutlookNameSpace: Variant;
function OutlookActiveExplorer: Variant;
procedure ConnectOutlook(Connect:Boolean);
function CurrentUser:String;
// Default folders
function Contacts:Variant;
function Calendar:Variant;
function DeletedItems:Variant;
function Drafts:Variant;
function Inbox:Variant;
function Journal:Variant;
function Notes:Variant;
function Outbox:Variant;
function SentMail:Variant;
function Tasks:Variant;
function TopFolders(Index:Variant):Variant;
// Selection handling (active explorer)
function GetSelection(Index:Word):Variant;
function GetSelectionCount:Word;
// Contact handling (DefaultFolder-Contacts)
function CreateContact:Variant;
function Contact(Index:Variant):Variant;
function ContactCount:Word;
procedure ShowContact(Index:Word);
procedure DeleteContact(MyContact:Variant);
function FindContact(FindWhat:String):Variant;
// Mail handling
function CreateMail(Recipient:String):Variant;
function AddRecipientToMail(MyMail:Variant; Recipient:String):Variant;
function AddAttachmentToMail(MyMail:Variant; FileName:String):Variant;
// Other outlook objects
function CommandBars:Variant;
published
property Connected : Boolean read Active write ConnectOutlook;
property OLEObject : String read MyOLEObject write MyOLEObject;
property OLENameSpace : String read MyOLENameSpace write MyOLENameSpace;
property OnConnect: TNotifyEvent read fOnConnected write fOnConnected;
property OnDisConnect: TNotifyEvent read fOnDisConnected write fOnDisConnected;
end;
procedure Register;
implementation
{$r Outlooktools.res}
procedure TOutlookConnect.ConnectOutlook(Connect:Boolean);
begin
if Connect then
begin
try
MyOlApp:=CreateOleObject(OLEObject);
MyNameSpace:=MyOlApp.GetNamespace(OLENameSpace);
if (Assigned(fOnConnected)) then
fOnConnected(Self);
except
raise Exception.Create('Outlook registration failed');
end;
end else
begin
MyOlApp:=NULL;
MyNameSpace:=NULL;
if (Assigned(fOnDisConnected)) then
fOnDisConnected(Self);
end;
Active:=Connect;
end;
function TOutlookConnect.CurrentUser:String;
begin
if not Active then
raise Exception.Create('No connection to outlook');
try
Result:=MyNameSpace.CurrentUser.Name;
except
raise Exception.Create('Cannot import Item');
end;
end;
function TOutlookConnect.Contact(Index:Variant) : Variant;
begin
if not Active then
raise Exception.Create('No connection to outlook');
try
Result:=myNameSpace.GetDefaultFolder(olFolderContacts).Items[Index];
except
raise Exception.Create('Cannot import Item');
end;
end;
function TOutlookConnect.Contacts : Variant;
begin
if not Active then
raise Exception.Create('No connection to outlook');
try
Result:=myNameSpace.GetDefaultFolder(olFolderContacts);
except
raise Exception.Create('Cannot connect to Contacts');
end;
end;
function TOutLookConnect.ContactCount:Word;
begin
if not Active then
raise Exception.Create('No connection to outlook');
try
Result:=myNameSpace.GetDefaultFolder(olFolderContacts).Items.Count;
except
Result:=0;
end;
end;
function TOutlookConnect.GetSelection(Index:Word): Variant;
begin
if not Active then
raise Exception.Create('No connection to outlook');
try
Result:=MyOlApp.ActiveExplorer.Selection(Index);
except
raise Exception.Create('No item selected');
end;
end;
function TOutlookConnect.GetSelectionCount:Word;
begin
if not Active then
raise Exception.Create('No connection to outlook');
try
Result:=MyOlApp.ActiveExplorer.Selection.Count;
except
result:=0;
end;
end;
function TOutlookConnect.CreateContact:Variant;
var
MyContact:Variant;
begin
if not Active then
raise Exception.Create('No connection to outlook');
try
MyContact:=myNameSpace.GetDefaultFolder(olFolderContacts).Items.Add;
Result:=MyContact;
except
raise Exception.Create('Cannot create contact');
end;
end;
procedure TOutlookConnect.DeleteContact(MyContact:Variant);
begin
if not Active then
raise Exception.Create('No connection to outlook');
try
MyContact.Delete;
except
raise Exception.Create('Cannot delete item');
end;
end;
function TOutlookConnect.FindContact(FindWhat:String):Variant;
begin
if not Active then
raise Exception.Create('No connection to outlook');
try
Result:=myNameSpace.GetDefaultFolder(olFolderContacts).Items.Find(FindWhat);
except
raise Exception.Create('Error finding Item');
end;
end;
function TOutlookConnect.CreateMail(Recipient:String):Variant;
var
MyMail:Variant;
begin
if not Active then
raise Exception.Create('No connection to outlook');
try
MyMail:=myNameSpace.GetDefaultFolder(olFolderOutBox).Items.Add;
MyMail.To:=Recipient;
Result:=MyMail;
except
raise Exception.Create('Cannot create mail');
end;
end;
function TOutlookConnect.AddRecipientToMail(MyMail:Variant; Recipient:String):Variant;
var
MyRecipient:Variant;
begin
if not Active then
raise Exception.Create('No connection to outlook');
try
MyRecipient:=MyMail.Recipients.Add(Recipient);
Result:=MyRecipient;
except
raise Exception.Create('Cannot access mail');
end;
end;
function TOutlookConnect.AddAttachmentToMail(MyMail:Variant; FileName:String):Variant;
var
MyAttachment:Variant;
begin
if not Active then
raise Exception.Create('No connection to outlook');
try
MyAttachment:=MyMail.Attachments.Add(FileName);
Result:=MyAttachment;
except
raise Exception.Create('Cannot access mail');
end;
end;
function TOutlookConnect.OutlookApplication: Variant;
begin
Result:=MyOlApp;
end;
function TOutlookConnect.OutlookNameSpace: Variant;
begin
Result:=MyNameSpace;
end;
function TOutlookConnect.OutlookActiveExplorer: Variant;
begin
Result:=MyOlApp.ActiveExplorer;
end;
function TOutlookConnect.CommandBars : Variant;
begin
if not Active then
raise Exception.Create('No connection to outlook');
Result:=MyOlApp.ActiveExplorer.CommandBars;
end;
Procedure TOutLookConnect.ShowContact(Index:Word);
var
MyContact:Variant;
begin
if not Active then
raise Exception.Create('No connection to outlook');
try
MyContact:=myNameSpace.GetDefaultFolder(olFolderContacts).Items[Index];
MyContact.Display;
except
raise Exception.Create('Cannot display contact');
end;
end;
function TOutlookConnect.Calendar:Variant;
begin
if not Active then
raise Exception.Create('No connection to outlook');
Result:=myNameSpace.GetDefaultFolder(olFolderCalendar);
end;
function TOutlookConnect.DeletedItems:Variant;
begin
if not Active then
raise Exception.Create('No connection to outlook');
Result:=myNameSpace.GetDefaultFolder(olFolderDeletedItems);
end;
function TOutlookConnect.Drafts:Variant;
begin
if not Active then
raise Exception.Create('No connection to outlook');
Result:=myNameSpace.GetDefaultFolder(olFolderDrafts);
end;
function TOutlookConnect.Inbox:Variant;
begin
if not Active then
raise Exception.Create('No connection to outlook');
Result:=myNameSpace.GetDefaultFolder(olFolderInbox);
end;
function TOutlookConnect.Journal:Variant;
begin
if not Active then
raise Exception.Create('No connection to outlook');
Result:=myNameSpace.GetDefaultFolder(olFolderJournal);
end;
function TOutlookConnect.Notes:Variant;
begin
if not Active then
raise Exception.Create('No connection to outlook');
Result:=myNameSpace.GetDefaultFolder(olFolderNotes);
end;
function TOutlookConnect.Outbox:Variant;
begin
if not Active then
raise Exception.Create('No connection to outlook');
Result:=myNameSpace.GetDefaultFolder(olFolderOutbox);
end;
function TOutlookConnect.SentMail:Variant;
begin
if not Active then
raise Exception.Create('No connection to outlook');
Result:=myNameSpace.GetDefaultFolder(olFolderSentMail);
end;
function TOutlookConnect.Tasks:Variant;
begin
if not Active then
raise Exception.Create('No connection to outlook');
Result:=myNameSpace.GetDefaultFolder(olFolderTasks);
end;
function TOutlookConnect.TopFolders(Index:Variant):Variant;
begin
if not Active then
raise Exception.Create('No connection to outlook');
Result:=myNameSpace.Folders.Item(Index);
end;
constructor TOutlookConnect.Create(AOwner : TComponent);
begin
inherited Create(AOwner);
if Active then ConnectOutlook(True);
if OLEObject='' then OLEObject:='Outlook.Application';
if OLENameSpace='' then OLENameSpace:='MAPI';
end;
destructor TOutlookConnect.Destroy;
begin
ConnectOutlook(False);
inherited Destroy;
end;
procedure Register;
begin
RegisterComponents('Outlook', [TOutlookConnect]);
end;
end.