Recent

Author Topic: tvPlanit - how to get the name of a cathegory?  (Read 865 times)

Nicole

  • Hero Member
  • *****
  • Posts: 1308
tvPlanit - how to get the name of a cathegory?
« on: August 20, 2022, 02:39:43 pm »
Below is my search function for tvplanit, which works fine.
It shall return the event name (fine), the date (fine) and the category, where the word is found (NOT fine).

Please see the method below and the line, the arrow points on.
What do I have to change there? Thanks.
(I do not show my not-working-function, where I tried it, because it looks so strange, that I feel embarrassed.


Code: Pascal  [Select][+][-]
  1. // sucht nach einem Wort in einem Eintrag , gibt Datum und uU in Var cat die Katheogrie zurück
  2. function TTvPlanItFrame.SucheWortInEvent(Var Nadel: string; Var ab_id: integer; Var cat: string): TDateTime;
  3. var res: TVpResource;
  4.     event: TVpEvent;
  5.     i, j: Integer;
  6.     s1, s2: string;
  7.  
  8. begin
  9.   Result := 0;
  10.   cat:= ''; // Kathegorie
  11.  
  12.   Nadel:=trim(Nadel);  // Nadel = needle = searchstring
  13.   If Nadel = '' then begin
  14.        ShowMessage('Bitte einen Suchbegriff wählen!');
  15.        exit;
  16.   end;
  17.  
  18.   res := VpControlLink_my.Datastore.Resource;    // war VpControlLink1
  19.   if res = nil then exit;
  20.  
  21.   if ab_id > res.Schedule.EventCount-1 then exit; // dann sucht er mehr als da sind
  22.  
  23.   for i := ab_id to res.Schedule.EventCount-1 do
  24.   begin
  25.     event := res.Schedule.GetEvent(i);  // findet nur komplette Entsprechung
  26.     s1:=UpperCase(Nadel);
  27.     s2:=UpperCase(event.Description);
  28.     if   Pos(s1,s2) > 0 then  // der Substring muss zuerst stehen
  29.     begin
  30.       Result := RecodeYear(event.StartTime, YearOf(Now));
  31.       Nadel:=event.Description;
  32. ======>      cat:= Kategorie_AlsWort(res, event.Category);
  33.       ab_id:=i;
  34.       exit;
  35.     end;
  36.   end;
  37. end;                              

wp

  • Hero Member
  • *****
  • Posts: 13424
Re: tvPlanit - how to get the name of a cathegory?
« Reply #1 on: August 20, 2022, 05:04:19 pm »
Unlike Tasks and Contacts which have fixed categories (type TVpCategoryType = (ctBusiness, ctClients, ctFamily, ctOther, ctPersonal), and string conversion in CategoryLabel(categorytype)), events have more flexible categories which are defined in the CatagoryColorMap of the datastore which provides 10 categories of type TVpCategoryInfo (Category0..Category9). These are the public/published methods/properties of TVpCategoryColorMap:
Code: Pascal  [Select][+][-]
  1. type
  2.   TVpCategoryColorMap = class(TPersistent)
  3.     ...
  4.   public
  5.     ...
  6.     function GetColor(AIndex: Integer): TColor;
  7.     function GetName(AIndex: Integer):string;
  8.     function GetCategory(AIndex: Integer): TVpCategoryInfo;
  9.     function GetCategoryName(AIndex: Integer): String;
  10.     function IndexOfCategory(AName: String): Integer;
  11.     function IndexOfFirstUnusedCategory: Integer;
  12.     procedure SetCategoryName(AIndex: Integer; AName: String);
  13.   published
  14.     property Category0: TVpCategoryInfo index 0 read GetCategory write SetCat;
  15.     property Category1: TVpCategoryInfo index 1 read GetCategory write SetCat;
  16.     property Category2: TVpCategoryInfo index 2 read GetCategory write SetCat;
  17.     property Category3: TVpCategoryInfo index 3 read GetCategory write SetCat;
  18.     property Category4: TVpCategoryInfo index 4 read GetCategory write SetCat;
  19.     property Category5: TVpCategoryInfo index 5 read GetCategory write SetCat;
  20.     property Category6: TVpCategoryInfo index 6 read GetCategory write SetCat;
  21.     property Category7: TVpCategoryInfo index 7 read GetCategory write SetCat;
  22.     property Category8: TVpCategoryInfo index 8 read GetCategory write SetCat;
  23.     property Category9: TVpCategoryInfo index 9 read GetCategory write SetCat;
  24.   end;
  25.  
  26. type
  27.   TVpCategoryInfo= class(TPersistent)
  28.   ...
  29.   published
  30.     property BackgroundColor: TColor
  31.       read FBackgroundColor write SetBackgroundColor default clWindow;
  32.     property Bitmap: TBitmap read FBitmap write SetBitmap;
  33.     property Color: TColor read FColor write SetColor;
  34.     property Description: string read FDescription write SetDescription;
  35.     property ImageIndex: TImageIndex read FImageIndex write SetImageIndex default -1;
  36.     property CategoryIndex: Integer read FCategoryIndex;
  37.     property UseForAllDayEvents: Boolean read FAllDayEvents write FAllDayEvents default false;
  38.   end;

Returning to your question, how to get the name (property TVpCategoryInfo.Description) of an event category, you must know that event.Category is th index into the CategoryColorMap's categorinfo. Therefore, simply call the method GetCategoryName(index) (or GetName(index) which does the same) with the event's category info.

A fairly general function would be
Code: Pascal  [Select][+][-]
  1. function GetEventCategoryName(Event: TVpEvent): String;
  2. var
  3.   resource: TVpResource;
  4.   datastore: TVpCustomDatastore;
  5. begin
  6.   resource := Event.GetResource;
  7.   datastore := TVpCustomDatastore(resource.Owner.Owner);
  8.   Result := datastore.CategoryColorMap.GetCategoryName(Event.Category);
  9. end;

Nicole

  • Hero Member
  • *****
  • Posts: 1308
[solved] Re: tvPlanit - how to get the name of a cathegory?
« Reply #2 on: August 20, 2022, 05:12:13 pm »
That was easy!
Thank you.

I expected it, to be easy, and I am glad, not to have shown my verbose attempts. ;-)

 

TinyPortal © 2005-2018