Copyright © 2024 IMIBO. Privacy Statement
Request # 28
How to Save (store) Meetings/Appointments item to DataBase and synchronize them (one way)?
This example requires you to use a Microsoft Exchange account.
Code snip:
const AppDB = 'Appointment.db'; procedure TfrmMain.btCopyToDBClick(Sender: TObject); var CalendarItem: IMessage; GlobalObjectId: TBytes; Found: Boolean; aDateTime: TDateTime; Status: ULONG; sTemp: string; begin GlobalObjectId:=nil; if not Assigned(ListView.Selected) or not Assigned(ContentTable) then Exit; CalendarItem := FindCalendarItemFromRow(ListView.Selected.Index); if not Assigned(CalendarItem) then Exit; GlobalObjectId := GetNamedPropBinary(CalendarItem, OutlookMeetingNamedProp[idLidGlobalObjectId].GUID_ID^, OutlookMeetingNamedProp[idLidGlobalObjectId].PROP_ID); // Scanning for GlobalObjectId Found := False; if ClientDataSet.Active = False then begin ClientDataSet.CreateDataSet; if FileExists(FAppDB) then ClientDataSet.LoadFromFile(FAppDB); ClientDataSet.Active := True; end; ClientDataSet.DisableControls; try ClientDataSet.First; while not ClientDataSet.Eof do begin if IsSameBytes( {$IF NOT DEFINED(DELPHI2009)} GetAsBytes(TBinaryField(ClientDataSet.FieldByName('GlobalObjectId'))) {$ELSE} ClientDataSet.FieldByName('GlobalObjectId').AsBytes {$IFEND} , GlobalObjectId) then begin Found := True; Break; end; ClientDataSet.Next; end; finally ClientDataSet.EnableControls; end; if Found then begin ShowMessage('The Appointment is found at record ' + IntToStr(ClientDataSet.RecNo)); PageControl.ActivePageIndex := 1; end else begin ClientDataSet.Edit; ClientDataSet.Append; if GetNamedPropSysTime(CalendarItem, OutlookAppointmentNamedProp[idAppointmentStartWhole].GUID_ID^, OutlookAppointmentNamedProp[idAppointmentStartWhole].PROP_ID, aDateTime) then ClientDataSet.FieldByName('Start').AsDateTime := aDateTime; if GetNamedPropSysTime(CalendarItem, OutlookAppointmentNamedProp[idAppointmentEndWhole].GUID_ID^, OutlookAppointmentNamedProp[idAppointmentEndWhole].PROP_ID, aDateTime) then ClientDataSet.FieldByName('End').AsDateTime := aDateTime; sTemp := GetPropString(CalendarItem, PR_SUBJECT); ClientDataSet.FieldByName('Subject').AsString := sTemp; sTemp := GetNamedPropString(CalendarItem, OutlookAppointmentNamedProp[idLocation].GUID_ID^, OutlookAppointmentNamedProp[idLocation].PROP_ID); ClientDataSet.FieldByName('Location').AsString := sTemp; if GetNamedPropLong(CalendarItem, OutlookAppointmentNamedProp[idBusyStatus].GUID_ID^, OutlookAppointmentNamedProp[idBusyStatus].PROP_ID, Status) then ClientDataSet.FieldByName('Status').AsInteger := Status; {$IF NOT DEFINED(DELPHI2009)} SetAsBytes(TBinaryField(ClientDataSet.FieldByName('GlobalObjectId')), GlobalObjectId); {$ELSE} ClientDataSet.FieldByName('GlobalObjectId').AsBytes := GlobalObjectId; {$IFEND} ClientDataSet.Post; ShowMessage('The Appointment is copyed as record ' + IntToStr(ClientDataSet.RecordCount - 1)); PageControl.ActivePageIndex := 1; end; end;
Download Request #28 as Compiled Application
Download Project (DELPHI 10.4) ZIP file
Source Code: In package