From e6b0f403d56406d403baf394de46145b8e143447 Mon Sep 17 00:00:00 2001 From: wp_xxyyzz Date: Sat, 10 Sep 2016 18:27:50 +0000 Subject: [PATCH] tvplanit: Improve assignment of resource group to resource. git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@5146 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- components/tvplanit/examples/fulldemo/demomain.pas | 9 ++++----- components/tvplanit/source/vpbaseds.pas | 11 +++-------- components/tvplanit/source/vpdata.pas | 8 ++++---- components/tvplanit/source/vpdayview.pas | 7 +------ components/tvplanit/source/vpdayviewpainter.pas | 3 ++- components/tvplanit/source/vpmisc.pas | 4 ++-- components/tvplanit/source/vpweekview.pas | 7 +------ components/tvplanit/source/vpweekviewpainter.pas | 3 ++- 8 files changed, 19 insertions(+), 33 deletions(-) diff --git a/components/tvplanit/examples/fulldemo/demomain.pas b/components/tvplanit/examples/fulldemo/demomain.pas index d0fc5d07d..b8c59c9e2 100644 --- a/components/tvplanit/examples/fulldemo/demomain.pas +++ b/components/tvplanit/examples/fulldemo/demomain.pas @@ -405,16 +405,15 @@ end; // Creates a resource group at runtime procedure TMainForm.CreateResourceGroup; -const - GROUP_NAME = 'Res2 overlayed'; var datastore: TVpCustomDatastore; + grp: TVpResourceGroup; begin datastore := VpControlLink1.Datastore; - datastore.Resources.AddResourceGroup(GROUP_NAME, [1, 2]); + grp := datastore.Resources.AddResourceGroup('Res2 overlayed', [1, 2]); if datastore.Resource <> nil then - datastore.Resource.Group := GROUP_NAME else - datastore.Resource.Group := ''; + datastore.Resource.Group := grp else + datastore.Resource.Group := nil; // Important: This is not called internally so far! datastore.RefreshEvents; end; diff --git a/components/tvplanit/source/vpbaseds.pas b/components/tvplanit/source/vpbaseds.pas index 06cbc5103..0b8fa0666 100644 --- a/components/tvplanit/source/vpbaseds.pas +++ b/components/tvplanit/source/vpbaseds.pas @@ -805,22 +805,17 @@ procedure TVpCustomDatastore.UpdateGroupEvents; var i: Integer; event: TVpEvent; - grp: TVpResourceGroup; id: Integer; begin Resource.Schedule.ClearGroupEvents; - if Resource.Group = '' then begin + if Resource.Group = nil then begin NotifyDependents; exit; end; - grp := Resources.FindResourceGroupByName(Resource.Group); - if grp = nil then - exit; - - for i:=0 to grp.Count-1 do begin - id := grp[i].ResourceID; + for i:=0 to Resource.Group.Count-1 do begin + id := Resource.Group[i].ResourceID; if id = ResourceID then exit; LoadEventsOfResource(id); diff --git a/components/tvplanit/source/vpdata.pas b/components/tvplanit/source/vpdata.pas index 5f319ce2b..b0d2b0004 100644 --- a/components/tvplanit/source/vpdata.pas +++ b/components/tvplanit/source/vpdata.pas @@ -113,7 +113,7 @@ type FSchedule: TVpSchedule; FTasks: TVpTasks; FContacts: TVpContacts; - FGroup: String; // Name of ResourceGroup to be overlayed in event list. + FGroup: TVpResourceGroup; FActive: Boolean; // Internal flag whether to display this resource FNotes: string; FDescription: string; @@ -134,7 +134,7 @@ type procedure SetContacts(const Value: TVpContacts); procedure SetDeleted(Value: Boolean); procedure SetDescription(const Value: string); - procedure SetGroup(const AValue: String); + procedure SetGroup(const AValue: TVpResourceGroup); procedure SetNotes(const Value: string); procedure SetResourceID(const Value: Integer); procedure SetSchedule(const Value: TVpSchedule); @@ -156,7 +156,7 @@ type property Schedule: TVpSchedule read GetSchedule write SetSchedule; property Tasks: TVpTasks read FTasks write SetTasks; property Contacts: TVpContacts read FContacts write SetContacts; - property Group: String read FGroup write SetGroup; + property Group: TVpResourceGroup read FGroup write SetGroup; {$ifdef WITHRTTI} published @@ -944,7 +944,7 @@ begin end; end; -procedure TVpResource.SetGroup(const AValue: String); +procedure TVpResource.SetGroup(const AValue: TVpResourceGroup); begin FGroup := AValue; end; diff --git a/components/tvplanit/source/vpdayview.pas b/components/tvplanit/source/vpdayview.pas index 8d2a95f5b..6312b3634 100644 --- a/components/tvplanit/source/vpdayview.pas +++ b/components/tvplanit/source/vpdayview.pas @@ -1159,13 +1159,8 @@ end; {=====} procedure TVpDayView.PopupPickResourceGroupEvent(Sender: TObject); -var - grp: TVpResourceGroup; begin - if TMenuItem(Sender).Tag = 0 then - Datastore.Resource.Group := '' - else - Datastore.Resource.Group := TMenuItem(Sender).Caption; + Datastore.Resource.Group := TVpResourceGroup(TMenuItem(Sender).Tag); Datastore.UpdateGroupEvents; end; diff --git a/components/tvplanit/source/vpdayviewpainter.pas b/components/tvplanit/source/vpdayviewpainter.pas index 7c8f1e6c0..db0c32798 100644 --- a/components/tvplanit/source/vpdayviewpainter.pas +++ b/components/tvplanit/source/vpdayviewpainter.pas @@ -164,7 +164,8 @@ begin if AEvent.IsOverlayed then begin res := FDayView.Datastore.Resources.GetResource(AEvent.ResourceID); - Result := Format('[%s] %s', [res.Description, Result]); + if res <> nil then + Result := Format('[%s] %s', [res.Description, Result]); end; if FDayView.WrapStyle = wsNone then begin diff --git a/components/tvplanit/source/vpmisc.pas b/components/tvplanit/source/vpmisc.pas index ad043e33a..545f97d09 100644 --- a/components/tvplanit/source/vpmisc.pas +++ b/components/tvplanit/source/vpmisc.pas @@ -730,7 +730,7 @@ begin newSubItem.OnClick := AEventHandler; newSubItem.GroupIndex := 1; newSubItem.AutoCheck := true; - newSubItem.Checked := datastore.Resource.Group = ''; + newSubItem.Checked := datastore.Resource.Group = nil; newSubItem.Tag := 0; newItem.Add(newSubItem); @@ -747,7 +747,7 @@ begin newSubItem.OnClick := AEventHandler; newSubItem.GroupIndex := 1; newSubItem.AutoCheck := true; - newSubItem.Checked := (datastore.Resource.Group = grp.Caption); + newSubItem.Checked := (datastore.Resource.Group = grp); newSubItem.Tag := PtrInt(grp); newItem.Add(NewSubItem); end; diff --git a/components/tvplanit/source/vpweekview.pas b/components/tvplanit/source/vpweekview.pas index 1ce9a096d..f986c8514 100644 --- a/components/tvplanit/source/vpweekview.pas +++ b/components/tvplanit/source/vpweekview.pas @@ -1121,13 +1121,8 @@ begin end; procedure TVpWeekView.PopupPickResourceGroupEvent(Sender: TObject); -var - grp: TVpResourceGroup; begin - if TMenuItem(Sender).Tag = 0 then - Datastore.Resource.Group := '' - else - Datastore.Resource.Group := TMenuItem(Sender).Caption; + Datastore.Resource.Group := TVpResourceGroup(TMenuItem(Sender).Tag); Datastore.UpdateGroupEvents; end; diff --git a/components/tvplanit/source/vpweekviewpainter.pas b/components/tvplanit/source/vpweekviewpainter.pas index d9d12170e..07e0fa32f 100644 --- a/components/tvplanit/source/vpweekviewpainter.pas +++ b/components/tvplanit/source/vpweekviewpainter.pas @@ -95,7 +95,8 @@ begin if AEvent.IsOverlayed then begin res := FWeekView.Datastore.Resources.GetResource(AEvent.ResourceID); - Result := Format('[%s] %s', [res.Description, Result]); + if res <> nil then + Result := Format('[%s] %s', [res.Description, Result]); end; end;