Recent

Author Topic: [solved] tvPlanit - deleted event is still there  (Read 494 times)

Nicole

  • Hero Member
  • *****
  • Posts: 745
[solved] tvPlanit - deleted event is still there
« on: December 28, 2022, 08:28:40 pm »
There is a search function (to my mind it works fine), which gives me the number of the event, which shall be deleted.

The deletion event looks like this.

Code: Pascal  [Select][+][-]
  1. // deletes an event from tfPlanit by number
  2. procedure TTvPlanItFrame.LoescheEvent(Nr: integer);
  3. Var res: TVpResource;
  4.     event: TVpEvent;
  5.     i: Integer;
  6.  
  7. begin
  8.   res := VpControlLink_my.Datastore.Resource;    // war VpControlLink1
  9.   if res = nil then exit;
  10.  
  11.   for i := 0 to res.Schedule.EventCount-1 do  begin
  12.     if i = Nr then begin
  13.       event := res.Schedule.GetEvent(i);
  14.       res.Schedule.DeleteEvent(event);
  15.       break;
  16.     end;
  17.   end;
  18. end

After having called the method, I close down the tvPlanit-software and re-open it.
I had expected that the deleted events would be gone.
However, these events are still there.

What can I do?
« Last Edit: January 02, 2023, 01:19:11 pm by Nicole »

wp

  • Hero Member
  • *****
  • Posts: 10857
Re: tvPlanit - deleted event is still there
« Reply #1 on: December 28, 2022, 11:10:26 pm »
Call Datastore.PostEvents after deleting the resource from the Schedule.

Code: Pascal  [Select][+][-]
  1. procedure TForm1.LoescheEvent(Nr: integer);
  2. Var
  3.   res: TVpResource;
  4.   event: TVpEvent;
  5. begin
  6.   res := VpControlLink1.Datastore.Resource;
  7.   if res <> nil then
  8.   begin
  9.     event := res.Schedule.GetEvent(Nr);
  10.     res.Schedule.DeleteEvent(event);
  11.     VpIniDatastore1.PostEvents;
  12.   end;
  13. end;

BTW, no need to iterate over all events to find the one with the given index Nr.

And I just added an overloaded DeleteEvent to the Schedule which has the event index as parameter so that above code can be rewritten as:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.LoescheEvent(Nr: integer);
  2. Var
  3.   res: TVpResource;
  4. begin
  5.   res := VpControlLink1.Datastore.Resource;
  6.   if res <> nil then
  7.   begin
  8.     res.Schedule.DeleteEvent(Nr);
  9.     VpIniDatastore1.PostEvents;
  10.   end;
  11. end;

Nicole

  • Hero Member
  • *****
  • Posts: 745
Re: tvPlanit - deleted event is still there
« Reply #2 on: December 30, 2022, 05:12:39 pm »
Thank you for your answer, I wrote this now, - hm, but it does not work.
At the moment I have listed 3 event by my filter.
Hitting "delete" with the method below, makes vanish one line of those three (which may be a mistake in my loop as well).
The pre-problem is: Closing my software and re-open it makes those three lines re-appear. So there may be "deleted" one event, but this seems not to be saved back into the ini-datastore.

If you want it, I can zip my whole software and give you the filter criteria.
If not, here is the method, which makes
- vanish one of wanted 3 events (my be my mistake)
- restores this event again on re-start of the program


Code: Pascal  [Select][+][-]
  1. // löscht ein Event aus TvPlanner, und bei "false" auch aus meinen Dateien
  2. procedure TTvPlanItFrame.LoescheEvent(Nr: integer; nur_aus_tvPlanit: Boolean =  true);
  3. Var res: TVpResource;
  4.     event: TVpEvent;
  5.     KategorieNr: Integer;
  6.     datum: TDateTime;
  7.     beschreibung: string;
  8.  
  9. begin
  10.   res := VpControlLink_my.Datastore.Resource;    // war VpControlLink1
  11.   if res <> nil then
  12.       begin
  13.         event:=res.Schedule.GetEvent(Nr);
  14.         res.Schedule.DeleteEvent(event);
  15.         VpControlLink_my.DataStore.PostEvents;
  16.         if not nur_aus_tvPlanit then begin  // this is false and shall not matter
  17.            event:=res.Schedule.GetEvent(Nr);
  18.            datum:=event.StartTime;
  19.            beschreibung:=event.Description;
  20.            KategorieNr:=event.Category;
  21.            Erfolg.LoescheTerminAusDatei (datum, beschreibung, KategorieNr);
  22.       end; end;
  23. end;  

wp

  • Hero Member
  • *****
  • Posts: 10857
Re: tvPlanit - deleted event is still there
« Reply #3 on: December 30, 2022, 07:07:32 pm »
I am attaching a simple demo project in which you can delete all events of today by a button click (when you test this make sure to add some dummy events for "today" before you do this). It is working for me. If it is not working in your project you must have some logic error along the way. One possible candidate: Do you iterate the deletion loop downward?

Nicole

  • Hero Member
  • *****
  • Posts: 745
Re: tvPlanit - deleted event is still there
« Reply #4 on: January 02, 2023, 01:18:39 pm »
Thank you so much!

and: I am glad to have learned about the searching by data functionality besides.

 

TinyPortal © 2005-2018