Read-only Outlook calendar items

Add-in Express™ Support Service
That's what is more important than anything else

Read-only Outlook calendar items
 
Trevor Pegley




Posts: 22
Joined: 2006-12-11
Hi,

Is it possible to make Outlook calendar appointments read-only i.e. prevent users from moving or resizing them?

If not, is it possible to show a warning dialog after an appointment has been edited to say that the changes will be lost once Outlook has closed?

TIA

Trev
Posted 25 Jan, 2007 10:01:14 Top
Dmitry Kostochko


Add-in Express team


Posts: 2875
Joined: 2004-04-05
Hi Trevor,

You can try to use the TAppointmentItem.OnWrite event handler and restore the Start and End properties to their initial state. See the code below:

  TAddInModule = class(TadxCOMAddInModule)
    procedure adxCOMAddInModuleAddInInitialize(Sender: TObject);
    procedure adxCOMAddInModuleAddInFinalize(Sender: TObject);
  private
    FList: TObjectList;
    procedure DoWrite(ASender: TObject; var Cancel: WordBool);
  protected
  public
  end;

implementation

{$R *.dfm}

type
  TMyAppointmentItem = class(TAppointmentItem)
  private
    FStart: TDateTime;
    FEnd: TDateTime;
    FEntryID: WideString;
  public
    procedure ConnectTo(svrIntf: _AppointmentItem);
  end;

{ TMyAppointmentItem }

procedure TMyAppointmentItem.ConnectTo(svrIntf: _AppointmentItem);
begin
  inherited ConnectTo(svrIntf);
  FStart := svrIntf.Start;
  FEnd := svrIntf.End_;
  FEntryID := svrIntf.EntryID;
end;

{ TAddInModule }

procedure TAddInModule.adxCOMAddInModuleAddInInitialize(Sender: TObject);
var
  i: Integer;
  IFolder: MAPIFolder;
  IAppointment: _AppointmentItem;
  Item: TMyAppointmentItem;
begin
  FList := TObjectList.Create;

  IFolder := OutlookApp.GetNamespace('MAPI').GetDefaultFolder(olFolderCalendar);
  if Assigned(IFolder) then
    try
      for i := 1 to IFolder.Items.Count do begin
        IFolder.Items.Item(i).QueryInterface(IID__AppointmentItem, IAppointment);
        if Assigned(IAppointment) then
          try
            Item := TMyAppointmentItem.Create(nil);
            Item.ConnectTo(IAppointment);
            Item.OnWrite := DoWrite;
            FList.Add(Item);
          finally
            IAppointment := nil;
          end;
      end;
    finally
      IFolder := nil;
    end;
end;

procedure TAddInModule.adxCOMAddInModuleAddInFinalize(Sender: TObject);
begin
  FList.Free;
end;

procedure TAddInModule.DoWrite(ASender: TObject; var Cancel: WordBool);
var
  Index: Integer;
begin
  Index := FList.IndexOf(ASender);
  if Index 
>=
 0 then begin
    TMyAppointmentItem(ASender).Start := TMyAppointmentItem(FList[Index]).FStart;
    TMyAppointmentItem(ASender).End_ := TMyAppointmentItem(FList[Index]).FEnd;
  end;
end;


P.S. Note that we take up your forum requests in the order we receive them.
Besides, it may take us some time to investigate your issue. Please be sure we will let you know as soon as the best possible solution is found.

Posted 25 Jan, 2007 11:08:23 Top