Table of Contents

Managing calendars

A Google account holds several calendars, and TTMSFNCCloudGoogleCalendar keeps them in its Calendars collection. It reads the list, creates new calendars with their default reminders, updates them, and deletes them — all asynchronously, reporting through events. This chapter covers listing and creating calendars, editing or removing them, and reading the available event colors.

Listing and creating calendars

Call GetCalendars to load the account's calendars; OnGetCalendars fires when the list is ready and the Calendars collection is populated. Each TTMSFNCCloudGoogleCal exposes Summary, Description, Location, TimeZone, a Primary flag, and a DefaultReminders collection. Create a calendar by adding one to Calendars, setting its fields and any default reminders, and calling AddCalendar.

procedure TForm1.CalendarGetCalendars(Sender: TObject;
  const ARequestResult: TTMSFNCCloudBaseRequestResult);
var
  I: Integer;
  Cal: TTMSFNCCloudGoogleCal;
begin
  if not ARequestResult.Success then
    Exit;

  ListBox1.Clear;
  for I := 0 to FCalendar.Calendars.Count - 1 do
  begin
    Cal := FCalendar.Calendars[I];
    ListBox1.Items.AddObject(Cal.Summary, Cal);
  end;
end;

procedure TForm1.CreateCalendar;
var
  Cal: TTMSFNCCloudGoogleCal;
  Reminder: TTMSFNCCloudGoogleCalendarReminder;
begin
  Cal := FCalendar.Calendars.Add;
  Cal.Summary := 'Team calendar';
  Cal.Description := 'Shared team events';
  Cal.TimeZone := 'Europe/Paris';

  // A default reminder applied to events on this calendar.
  Reminder := Cal.DefaultReminders.Add;
  Reminder.Method := rmPopup;
  Reminder.Minutes := 60;

  FCalendar.AddCalendar(Cal); // result arrives in OnAddCalendar
end;

procedure TForm1.RemoveCalendar(ACal: TTMSFNCCloudGoogleCal);
begin
  FCalendar.DeleteCalendar(ACal); // result arrives in OnDeleteCalendar
end;

Updating and deleting calendars

Edit a calendar by changing the fields on the item from Calendars (which keeps its ID) and calling UpdateCalendar; remove one with DeleteCalendar. Each reports through its own event (OnUpdateCalendar, OnDeleteCalendar) — refresh the list there with GetCalendars.

The color palette

GetColors loads the palette Google offers for events into the ItemColors collection; each entry exposes a BackgroundColor. Read it after OnGetColors fires to present the available colors, which pair with the event Color property in Managing events.

Pitfalls

  • Edit the collection item for updates. Modify the existing TTMSFNCCloudGoogleCal (which has the server ID) and pass it to UpdateCalendar; a detached instance has no identity.
  • Act in the completion event. The Calendars collection and a new calendar's ID are only guaranteed once the matching event fires.
  • The primary calendar cannot be deleted — check Primary before offering a delete action.

See also