Recent

Author Topic: tvPlanit - how to generate a "good forever" (recurring) event by source code?  (Read 848 times)

Nicole

  • Sr. Member
  • ****
  • Posts: 349
I have a method, which allows to generate events by source code.
It reads

Code: Pascal  [Select][+][-]
  1. // Legt ein neues Event an im ausgewählten Thema und gibt die neue id davon zurück
  2. function TTvPlanItFrame.neuesEvent(AStartTime, AEndTime: TDateTime;
  3.   ACaption: String; ACategory: Integer): integer;
  4. var
  5.   event: TVpEvent;
  6.   id: Integer;
  7. begin
  8.    if VpInidatastore_Quelle.Resources.Count < 1 then begin
  9.         ShowMessage('Es muss mindestens ein Thema (=Ressource) angelegt werden. Bitte den Button "neu" klicken');
  10.         exit;     end;
  11.  
  12.   // Get the ID of the new event from the datastore
  13.   id := VpIniDataStore_Quelle.GetNextID('Events');
  14. //  id := self.VpIniDatastore_myLinkDazu.get.GetNextID('Events');
  15.   // Add the event...
  16.   event := VpIniDatastore_Quelle.Resource.Schedule.AddEvent(id, AStartTime, AEndTime);
  17.   // ... and specify some properties
  18.   event.Description := ACaption;
  19.   event.Category := ACategory;
  20.   event.Changed := true;
  21.   // Save the event in the datastore
  22.   VpIniDatastore_Quelle.PostEvents;
  23. end;

This works fine.
How to make it "recurring" forever?

wp

  • Hero Member
  • *****
  • Posts: 10051
Set EndTime to pseudo-"infinity" - I think Dec 31, 9999 (EndTime := EncodeDate(9999,12,31)) is the largest date that can be used as a TDateTime.

Nicole

  • Sr. Member
  • ****
  • Posts: 349
thank you for your answer.
Now I am puzzled.

This "starttime" and "endtime" colored me for all day events the whole dayView. As I do not want this, I made all-day-events "taking place" every day at the same time. This means, if I insert e.g. a birthday, I insert it between 10:00 and 11:00 to have a nice overview every day of what the day will bring.

Back to the problem: I though "endtime" would be 11:00?

In other words: Please explain which parameter to use best for "endtime" of an event versus "endtime" of its alert.

wp

  • Hero Member
  • *****
  • Posts: 10051
I meant "recurringendtime" (or similar, I'm not at my PC now and during the next days). Just look at the sourcecode (vpdata)

Nicole

  • Sr. Member
  • ****
  • Posts: 349
Thank you so much for answering never the less!
I will try it.

And: I am so glad, to have this tvPlanit!!
By translating my old code from TMS, I discover that much, which is even easier in tvPlanit.

Nicole

  • Sr. Member
  • ****
  • Posts: 349
does not work yet:

I tried this
Code: Pascal  [Select][+][-]
  1.   if ACategory = 3 then begin  // bei Jahrestagen wird die Wiederholung
  2.     dat:=EncodeDate(2050,12,31);   // "für immer" eingetragen
  3.     event.RepeatRangeEnd:=dat;
  4.   end;

Too high a year resulted in an exception.
vp data, line 1086

Code: Pascal  [Select][+][-]
  1. function TVpResource.GetSchedule: TVpSchedule;
  2. begin
  3.   if FSchedule = nil then
  4.     FSchedule := TVpSchedule.Create(self);
  5.   result := FSchedule;
  6. end;


This above works without exception, but does not do, what it should.
It does not repeat, e.g. in the year 2024.

What do you think about the idea to write "recurring" events for 5 years on startup instead?


PascalDragon

  • Hero Member
  • *****
  • Posts: 4552
  • Compiler Developer
Maybe the year 2038 problem of Linux :-) see https://de.wikipedia.org/wiki/Jahr-2038-Problem#:~:text=Die%20Unixzeit%20z%C3%A4hlt%20die%20seit,231%E2%88%921)%20%C3%BCberschreiten.

The components that Nicole is using are based on TDateTime which does not have this problem.

 

TinyPortal © 2005-2018