From 8b0e5c6f3e613257ee15e163910ad67585737306 Mon Sep 17 00:00:00 2001 From: wp_xxyyzz Date: Sun, 11 Sep 2016 08:14:11 +0000 Subject: [PATCH] tvplanit: Use resource description if resourcegroup caption is empty. git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@5150 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- .../tvplanit/examples/fulldemo/demomain.pas | 4 ++- components/tvplanit/source/vpdata.pas | 29 ++++++++++++------- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/components/tvplanit/examples/fulldemo/demomain.pas b/components/tvplanit/examples/fulldemo/demomain.pas index 044af045c..53e3580c7 100644 --- a/components/tvplanit/examples/fulldemo/demomain.pas +++ b/components/tvplanit/examples/fulldemo/demomain.pas @@ -405,12 +405,14 @@ end; // Creates a resource group at runtime procedure TMainForm.CreateResourceGroup; +const + NAME_OF_GROUP = ''; // empty --> use resource description var datastore: TVpCustomDatastore; grp: TVpResourceGroup; begin datastore := VpControlLink1.Datastore; - grp := datastore.Resources.AddResourceGroup('Res2 overlayed', [1, 2]); + grp := datastore.Resources.AddResourceGroup([1, 2], NAME_OF_GROUP); grp.ReadOnly := true; grp.Pattern := opDiagCross; if datastore.Resource <> nil then diff --git a/components/tvplanit/source/vpdata.pas b/components/tvplanit/source/vpdata.pas index 5d6def407..19d0fbe50 100644 --- a/components/tvplanit/source/vpdata.pas +++ b/components/tvplanit/source/vpdata.pas @@ -88,7 +88,8 @@ type constructor Create(Owner: TObject); destructor Destroy; override; function AddResource(ResID: Integer): TVpResource; - function AddResourceGroup(ACaption: String; const AResIDs: array of Integer): TVpResourceGroup; + function AddResourceGroup(const AResIDs: array of Integer; + ACaption: String = ''): TVpResourceGroup; procedure ClearResources; procedure ClearResourceGroups; function FindResourceByName(AName : string) : TVpResource; @@ -194,7 +195,7 @@ type function GetItem(AIndex: Integer): TVpResource; procedure SetPattern(AValue: TVpOverlayPattern); public - constructor Create(AOwner: TVpResources; ACaption: String; AResourceID: Integer); + constructor Create(AOwner: TVpResources; AResourceID: Integer; ACaption: String); destructor Destroy; override; function AddID(AResourceID: Integer): Integer; function AsString(ASeparator: Char = ';'): String; @@ -730,23 +731,30 @@ begin end; end; -function TVpResources.AddResourceGroup(ACaption: String; - const AResIDs: Array of Integer): TVpResourceGroup; +function TVpResources.AddResourceGroup(const AResIDs: Array of Integer; + ACaption: String = ''): TVpResourceGroup; var grp: TVpResourceGroup; + res: TVpResource; i: Integer; begin - if (ACaption = '') then - raise Exception.Create('Caption of resource group must not be empty'); - if Length(AResIDs) < 2 then raise Exception.Create('Resource group must contain at least one additional resource.'); + // Use resource descriptions if ACaption is not specified or empty. + if ACaption = '' then begin + for i:=Low(AResIDs) + 1 to High(AResIDs) do begin + res := GetResource(AResIDs[i]); + ACaption := ACaption + ', ' + res.Description; + end; + if ACaption <> '' then Delete(ACaption, 1, 2); + end; + // Enforce unique group name. grp := FindResourceGroupByName(ACaption); if grp = nil then begin // Index 0 refers to the resource to which the other resources are added. - Result := TVpResourceGroup.Create(Self, ACaption, AResIDs[0]); + Result := TVpResourceGroup.Create(Self, AResIDs[0], ACaption); FResourceGroups.Add(Result); end else begin grp.Clear; // Make sure that the group is empty before adding overlayed resources @@ -984,14 +992,15 @@ end; (*****************************************************************************) { TVpResourceGroup } (*****************************************************************************) -constructor TVpResourceGroup.Create(AOwner: TVpResources; ACaption: String; - AResourceID: Integer); +constructor TVpResourceGroup.Create(AOwner: TVpResources; AResourceID: Integer; + ACaption: String); begin inherited Create; FOwner := AOwner; FResourceID := AResourceID; FCaption := ACaption; FPattern := opBDiagonal; + FReadOnly := true; Clear; end;