Recent

Author Topic: [solved] tvPlanit - how to search for an event?  (Read 475 times)

Nicole

  • Hero Member
  • *****
  • Posts: 972
[solved] tvPlanit - how to search for an event?
« on: July 21, 2022, 04:20:25 pm »
If I forgot Bett'y wedding day - how to find the event?
« Last Edit: July 26, 2022, 02:30:42 pm by Nicole »

wp

  • Hero Member
  • *****
  • Posts: 11922
Re: tvPlanit - how to search for an event?
« Reply #1 on: July 21, 2022, 05:48:18 pm »
There is no Search facility, but it is easy to implement. Each resouce (type TVpResource) provides the following list-like objects:
  • Schedule: contains the events. Call Resource.Schedule.GetEvent(i) to get the event (type TVpEvent) at index i. There are EventCount events.
  • Tasks: contains the tasks. Call Resource.Tasks.GetTask(i) to get the task (type TVpTask) as index i. There are Count tasks.
  • Contacts: Contains the contacts. Call Resource.Contacts.GetContact(i) to get the contact (type TVpContact) at index i. There are Count contacts. Search by name via FindContactByName and FindContactIndexByName (Problem: compares only the last name!!! - to be fixed)
If you know that there is an event having the description "Betty's wedding day", you could iterate over the resource's Schedule and compare each event's description with that search text. Untested:
Code: Pascal  [Select][+][-]
  1. function TForm1.FindBettysWeddingDay: TDateTime;
  2. var
  3.   res: TVpResource;
  4.   event: TVpEvent;
  5.   i: Integer;
  6. begin
  7.   Result := 0;
  8.   res := VpControlLink1.Datastore.Resource;
  9.   if res = nil then
  10.     exit;
  11.  
  12.   for i := 0 to res.Schedule.EventCount-1 do
  13.   begin
  14.     event := res.Schedule.GetEvent(i);
  15.     if SameText(event.Description, 'Betty''s wedding day') then
  16.     begin
  17.       Result := RecodeYear(event.StartTime, YearOf(Now));
  18.       exit;
  19.     end;
  20.   end;
  21. end;

Nicole

  • Hero Member
  • *****
  • Posts: 972
Re: tvPlanit - how to search for an event?
« Reply #2 on: July 26, 2022, 02:30:18 pm »
your are really good, thank you so much.
Here comes the tested version.
I just brushed your code slightly:


add in uses:

DateUtils


Call by a button's click event by:


Code: Pascal  [Select][+][-]
  1. procedure TForm_Notizen.Button_SearchCalendarClick(Sender: TObject);
  2. Var Hit: TDateTime;
  3. begin
  4.   Hit:=TvPlanItFrame.SucheEvent('test');
  5.   ShowMessage(DateToStr(Hit));
  6. end;

Code: Pascal  [Select][+][-]
  1. // searches for an event in tVPlanit
  2. function TTvPlanItFrame.SucheEvent(Nadel: string): TDateTime;
  3.  
  4. var
  5.   res: TVpResource;
  6.   event: TVpEvent;
  7.   i: Integer;
  8. begin
  9.   Result := 0;
  10.  
  11.   Nadel:=trim(Nadel);  // Nadel = needle = searchstring
  12.   If Nadel = '' then begin
  13.        ShowMessage('Bitte einen Suchbegriff wählen!'); // = "please choose something to search for"
  14.        exit;
  15.   end;
  16.  
  17.   res := VpControlLink_my.Datastore.Resource;   // i.e. VpControlLink1
  18.   if res = nil then
  19.     exit;
  20.  
  21.   for i := 0 to res.Schedule.EventCount-1 do
  22.   begin
  23.     event := res.Schedule.GetEvent(i);
  24.     if SameText(event.Description, Nadel) then
  25.     begin
  26.       Result := RecodeYear(event.StartTime, YearOf(Now)); // needs dateUtils
  27.       exit;
  28.     end;
  29.   end;
  30. end;

 

TinyPortal © 2005-2018