[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 923
  • Last Modified:

Delphi Access to Outlook Calendar

Hello,

I have D5 Pro....  I am looking to find a way to read (and maybe write, but DEFINITELY read) an Outlook calendar. I have tried to find a simple, and ideally free component, but to no avail.  I would prefer to stay away from the Outlook Server component, but I may not have any choice.  Who can help?  Sample code or a URL to a free component wins 500 points....

Thanks
George S
0
gspears060598
Asked:
gspears060598
1 Solution
 
danielluyoCommented:
CDO or MAPI are not a choice??? they come with Outlook and you can use them to read and write anything Mail Calendar Notes ToDo, etc
0
 
cqhallCommented:
I read a shared calendar using the Outlook Server component (OutlookApplication) and populate a database with its contents.  The code below is extracted from a working application, but I may have cut a little too deep (missing var, etc)

First you need to establish a namespace and find your folder.  If you are looking for a shared folder, then you can loop through the root folders, its child folders, etc until you find the target folder.

Function TForm1.FindRootFolder(NmSpace: NameSpace; FolderName: string): MAPIFolder;
var
 fldrs: Folders;
 fldr: MapiFolder;
begin
 Fldrs:=nmSpace.Folders;
 fldr:=Fldrs.GetFirst;
 result:=nil;
 While fldr<>nil do
 begin
  if AnsiSameText(fldr.Name,foldername) then // case insensitive match
  begin
   result:=fldr;
   break;
  end;
  fldr:=Fldrs.GetNext;
 end;
end;
 
procedure TForm1.btnFoldersClick(Sender: TObject);
var
 fldrs: Folders;
 fldr: MapiFolder;
 RP: RecurrencePattern;
 RT: olRecurrenceType;
 dt,
 ex_modified,
 ex_created,
 ex_recurStart,
 ex_recurEnd,
 ex_active,
 ex_inactive: tdatetime;
 len : integer;
 subj,
 st: string;

begin
 NmSpace := OutlookApplication1.GetNamespace('MAPI');
 NmSpace.Logon('', '', False, False);
 fldr:=FindRootFolder(NmSpace,'Mailbox - Hall, Charles');
 cnt:=fldr.items.count;
 for i:=1 to cnt do
 try
  application.title:=inttostr(100*i div cnt)+'%';
  application.processmessages;
  if btnBreak.focused then //escape route
  begin
   btnUpdate.enabled:=true;
   btnBreak.enabled:=false;
   exit;
  end;
  Appt:=fldr.Items.Item(i) as AppointmentItem;
  with Appt do
  begin
   subj:=trim(subject);                         // SUBJECT from Exchange
   ex_active:=start;
   ex_inactive:=end_;
   ex_created:=CreationTime;          // TIME_CREATED in Exchange
   ex_modified:=LastModificationTime; // TIME_MODIFIED in Exchange
   if IsRecurring then
   begin
    RP:=GetRecurrencePattern;
    len:=RP.Interval;
    ex_recurStart:=rp.PatternStartDate;
    ex_recurEnd:=rp.PatternEndDate;
    case RP.RecurrenceType of
     olRecursDaily: st:='Daily';
     olRecursWeekly:
     begin
      case rp.DayOfWeekMask of
       olSunday: st:='Sunday';
       olMonday: st:='Monday';
       olTuesday: st:='Tuesday';
       olWednesday: st:='Wednesday';
       olThursday: st:='Thursday';
       olFriday: st:='Friday';
       olSaturday: st:='Saturday';
       else st:='????'
      end;
      st:='Weekly - '+st;
     end;
     olRecursMonthly: st:='Monthly';
     olRecursMonthNth: st:='MonthlyNth';
     olRecursYearly: st:='Yearly';
     olRecursYearNth: st:='YearNth'
     else st:='????';
    end;
    dt:=ex_recurStart;
    repeat
     case RP.RecurrenceType of
      olRecursDaily: dt:=dt+1;
      olRecursWeekly: dt:=dt+7;
      olRecursMonthly: dt:=incmonth(dt,1);
      olRecursYearly: dt:=incMonth(dt,12);
     end;
    until dt>ex_recurEnd;
   end;
  end;
 end;
end;

To add a new appoint, use something like...

   Appt:=devFolder.Items.Add(olAppointmentItem) as AppointmentItem;
   Appt.Subject:=Subject;
   Appt.Location:=Location;
   Appt.Body:=body;
   Appt.Start:=Start;
   Appt.End_:=End_;
   Appt.Duration:=Duration;
   Appt.Categories:=Categories;
   if Appt.IsRecurring then
   begin
     newRP:=RecurrencePattern;
     newRP.PatternStartDate:=PatternStartDate;
     newRP.PatternEndDate:=PatternEndDate;
     newRP.RecurrenceType:=RecurrenceType;
   end;
   Appt.Save;

Chuck Hall
0
 
gspears060598Author Commented:
Outstanding answer.... Apologies for the delay in awarding the points...
GS
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now