Reading your calendar
Posted: (EET/GMT+2)
Reading your calendar
Aug 1, 2000
Delphi 5 Professional & Enterprise
Although Microsoft Outlook is a great personal information manager (PIM) application, it lacks some features you really would like to have. Fortunately enough Outlook has a great API (application programming interface) that can be used to access Outlook objects using COM interfaces. For example, Delphi can be used to easily read your calendar.
Delphi 5 introduced those familiar Office components that can be found from the component palette's Servers tab. From there, you can find the TOutlookApplication component that is the key to accessing Outlook. Of course, you are free to use other ways to access Outlook (old-style OLE Automation for example), but the components provide a convenient way to do what you want.
Accessing Outlook
To start accessing Outlook, it is easiest to drop a TOutlookApplication component onto a form. From there, you need to call the Connect method, and then start to use the appropriate properties and methods of the component. For example, if you need to programmatically access the calendar feature in your Outlook you could connect to Outlook like this:
nsMAPI := GetNamespace('MAPI');
nsMAPI.Logon('',EmptyParam,EmptyParam,EmptyParam);
mfCalendar := nsMAPI.GetDefaultFolder(olFolderCalendar);
itAppointments := mfCalendar.Items;
Of course, describing the Outlook objects hierarchy is beyond the scope of this article, but a great introduction to the subject matter can be found from MSDN. There, the conference paper "Automating Microsoft Outlook 97" by Mike Gilbert is a great place to start.
Reading the calendar
Once you've got a grip of the Appointments folder (as the Calendar is called in the API), you can enumerate it by using the Item method of the Items dispatch interface. Because it is easy to get the starting and ending date of an appointment by reading the Start and End properties, you could also show them in a calendar-like grid like this:

For simplicity, the example application OutlookTest doesn't support recurring appointments, but by looking at the code you should quickly see how you can access Outlook to your heart's content. And once you can firmly access Outlook's objects from your Delphi applications, nothing prevents you from web-fying your Outlook. Then it is no more necessary to have Microsoft Exchange server installed!
Download the example code
Download readingyourcalendar.zip (209 kB) which contains the sample application "OutlookTest". You will need to have Delphi 5 to compile the application. The application has been tested with Microsoft Outlook 2000.
* * *
Want to access Microsoft Office applications from your code? Let us help you!