diff --git a/Source/BoldElements.pas b/Source/BoldElements.pas index 1d779c0..eaf44cb 100644 --- a/Source/BoldElements.pas +++ b/Source/BoldElements.pas @@ -197,12 +197,12 @@ TBoldExternalVariableList = class(TBoldObjectArray) function GetEnumerator: TBoldExternalVariableListTraverser; procedure Add(Variable: TBoldExternalVariable); overload; procedure Add(AName: string; AValue: TBoldElement); overload; - procedure Add(AName: string; AValue: string); overload; - procedure AddInteger(AName: string; AValue: integer); - procedure AddFloat(AName: string; AValue: Double); - procedure AddDateTime(AName: string; AValue: TDateTime); - procedure AddDate(AName: string; AValue: TDate); - procedure AddTime(AName: string; AValue: TTime); + procedure Add(AName: string; AValue: string; AEvaluator: TBoldEvaluator = nil); overload; + procedure AddInteger(AName: string; AValue: integer; AEvaluator: TBoldEvaluator = nil); + procedure AddFloat(AName: string; AValue: Double; AEvaluator: TBoldEvaluator = nil); + procedure AddDateTime(AName: string; AValue: TDateTime; AEvaluator: TBoldEvaluator = nil); + procedure AddDate(AName: string; AValue: TDate; AEvaluator: TBoldEvaluator = nil); + procedure AddTime(AName: string; AValue: TTime; AEvaluator: TBoldEvaluator = nil); property Variables[index: integer]: TBoldExternalVariable read GetVariables; default; property VariableByName[const aName: string]: TBoldExternalVariable read GetVariableByName; property AsCommaText: string read GetAsCommaText; @@ -983,9 +983,9 @@ procedure TBoldExternalVariableList.Add(Variable: TBoldExternalVariable); inherited Add(Variable); end; -procedure TBoldExternalVariableList.Add(AName, AValue: string); +procedure TBoldExternalVariableList.Add(AName, AValue: string; AEvaluator: TBoldEvaluator); begin - Add(TBoldOclVariable.CreateStringVariable(AName, AValue)); + Add(TBoldOclVariable.CreateStringVariable(AName, AValue, AEvaluator)); end; procedure TBoldExternalVariableList.Add(AName: string; AValue: TBoldElement); @@ -993,29 +993,29 @@ procedure TBoldExternalVariableList.Add(AName: string; AValue: TBoldElement); Add(TBoldOclVariable.Create(AName, AValue)); end; -procedure TBoldExternalVariableList.AddDate(AName: string; AValue: TDate); +procedure TBoldExternalVariableList.AddDate(AName: string; AValue: TDate; AEvaluator: TBoldEvaluator); begin - Add(TBoldOclVariable.CreateDateVariable(AName, AValue)); + Add(TBoldOclVariable.CreateDateVariable(AName, AValue, AEvaluator)); end; -procedure TBoldExternalVariableList.AddDateTime(AName: string; AValue: TDateTime); +procedure TBoldExternalVariableList.AddDateTime(AName: string; AValue: TDateTime; AEvaluator: TBoldEvaluator); begin - Add(TBoldOclVariable.CreateDateTimeVariable(AName, AValue)); + Add(TBoldOclVariable.CreateDateTimeVariable(AName, AValue, AEvaluator)); end; -procedure TBoldExternalVariableList.AddFloat(AName: string; AValue: Double); +procedure TBoldExternalVariableList.AddFloat(AName: string; AValue: Double; AEvaluator: TBoldEvaluator); begin - Add(TBoldOclVariable.CreateFloatVariable(AName, AValue)); + Add(TBoldOclVariable.CreateFloatVariable(AName, AValue, AEvaluator)); end; -procedure TBoldExternalVariableList.AddInteger(AName: string; AValue: integer); +procedure TBoldExternalVariableList.AddInteger(AName: string; AValue: integer; AEvaluator: TBoldEvaluator); begin - Add(TBoldOclVariable.CreateIntegerVariable(AName, AValue)); + Add(TBoldOclVariable.CreateIntegerVariable(AName, AValue, AEvaluator)); end; -procedure TBoldExternalVariableList.AddTime(AName: string; AValue: TTime); +procedure TBoldExternalVariableList.AddTime(AName: string; AValue: TTime; AEvaluator: TBoldEvaluator); begin - Add(TBoldOclVariable.CreateTimeVariable(AName, AValue)); + Add(TBoldOclVariable.CreateTimeVariable(AName, AValue, AEvaluator)); end; constructor TBoldExternalVariableList.Create(aOwnsVariables: boolean); diff --git a/Source/BoldIndex.pas b/Source/BoldIndex.pas index 3693cf3..f00f50e 100644 --- a/Source/BoldIndex.pas +++ b/Source/BoldIndex.pas @@ -743,6 +743,7 @@ procedure TBoldIntegerIndex.Clear(DestroyObjects: Boolean=false); end; end; fCount := 0; + SetCapacity(0); end; constructor TBoldIntegerIndex.Create; diff --git a/Source/BoldIndexableList.pas b/Source/BoldIndexableList.pas index bc1bae2..dd8f991 100644 --- a/Source/BoldIndexableList.pas +++ b/Source/BoldIndexableList.pas @@ -68,7 +68,7 @@ TBoldUnOrderedIndexableList = class(TBoldNonRefCountedObject) function AddIndex(BoldIndex: TBoldIndex): integer; procedure AddToAllIndexes(Item: TObject); procedure RemoveAndFreeIndex(var BoldIndex: TBoldIndex; DestroyObjects: Boolean); - procedure RemoveFromAllIndexes(Item: TObject); + function RemoveFromAllIndexes(Item: TObject): boolean; procedure SetIndexCapacity(NewCapacity: integer); function TraverserClass: TBoldIndexableListTraverserClass; virtual; property IndexCount: integer read GetIndexCount; @@ -82,7 +82,7 @@ TBoldUnOrderedIndexableList = class(TBoldNonRefCountedObject) procedure Add(Item: TObject); procedure Clear; procedure ItemChanged(Item: TObject); - procedure Remove(Item: TObject); + function Remove(Item: TObject): boolean; function CreateTraverser: TBoldIndexableListTraverser; function GetEnumerator: TBoldIndexableListTraverser; property Count: integer read GetCount; @@ -364,14 +364,19 @@ procedure TBoldUnOrderedIndexableList.AddToAllIndexes(Item: TObject); Indexes[i].Add(Item); end; -procedure TBoldUnOrderedIndexableList.RemoveFromAllIndexes(Item: TObject); +function TBoldUnOrderedIndexableList.RemoveFromAllIndexes(Item: TObject): boolean; var i: integer; begin if Assigned(Item) then + begin + result := (IndexCount > 0); for i := 0 to IndexCount-1 do if Assigned(Indexes[i]) then - Indexes[i].Remove(Item); + result := Indexes[i].Remove(Item) and result; + end + else + result := false; end; procedure TBoldUnOrderedIndexableList.Add(Item: TObject); @@ -387,14 +392,13 @@ procedure TBoldUnOrderedIndexableList.Add(Item: TObject); AddToAllIndexes(Item); end; -procedure TBoldUnOrderedIndexableList.Remove(Item: TObject); +function TBoldUnOrderedIndexableList.Remove(Item: TObject): boolean; begin - RemoveFromAllIndexes(item); + result := RemoveFromAllIndexes(item); if OwnsEntries then item.free; end; - procedure TBoldUnOrderedIndexableList.ItemChanged(Item: TObject); var i: integer; @@ -404,7 +408,6 @@ procedure TBoldUnOrderedIndexableList.ItemChanged(Item: TObject); Indexes[i].ItemChanged(Item); end; - procedure TBoldUnOrderedIndexableList.Clear; var i: Integer; @@ -416,7 +419,7 @@ procedure TBoldUnOrderedIndexableList.Clear; for i := 0 to IndexCount-1 do if assigned(Indexes[i]) then begin - Indexes[i].Clear(OwnsEntries and (IndicesToGo=1)); + Indexes[i].Clear(OwnsEntries and (IndicesToGo=1)); // only free from one (last) index dec(IndicesToGo); end; end; diff --git a/Source/BoldMeta.pas b/Source/BoldMeta.pas index c4f1583..ad36094 100644 --- a/Source/BoldMeta.pas +++ b/Source/BoldMeta.pas @@ -2252,10 +2252,11 @@ procedure TMoldElement.SetBoldTVByName(const Tag, value: string); begin TrimmedValue := BoldTrim(Value); Definition := DefaultBoldTVList.DefinitionForTag[Tag]; + // only set tag if it differs from default if Assigned(Definition) and (Definition.DefaultValue = TrimmedValue) then - // do Nothing - else - BoldTaggedValues.ValueByName[Tag] := TrimmedValue; + if BoldTaggedValues.ValueByName[Tag] = '' then + exit; + BoldTaggedValues.ValueByName[Tag] := TrimmedValue; end; function TMoldMember.GetManuallyDerived: Boolean; diff --git a/Source/BoldObjectListControllers.pas b/Source/BoldObjectListControllers.pas index 3c5dd5b..6880976 100644 --- a/Source/BoldObjectListControllers.pas +++ b/Source/BoldObjectListControllers.pas @@ -381,27 +381,19 @@ procedure TBoldObjectListController._ReceiveObjectDeleted( {$ENDIF} end; - procedure RemoveLocator(Locator: TBoldObjectLocator); - begin - if LocatorList.LocatorInList[Locator] then - begin - LocatorList.Remove(Locator); - Changed(beItemDeleted, [Locator]); - end; - end; - var DeletedLocator: TBoldObjectLocator; begin case OriginalEvent of beLocatorDestroying, beObjectDeleted: begin - DeletedLocator := (Originator as TBoldObject).BoldObjectLocator; - RemoveLocator(DeletedLocator); + DeletedLocator := Args[0].vObject as TBoldObjectLocator; + if LocatorList.Remove(DeletedLocator) then + Changed(beItemDeleted, [DeletedLocator]); end; beDestroying: begin - RemoveAllObjectsFromSystem(TBoldSystem(TBoldObjectList(Originator).OwningElement)); + RemoveAllObjectsFromSystem(Originator as TBoldSystem); end; else raise EBoldInternal.CreateFmt(sUnknownEvent, [classname]); @@ -410,7 +402,7 @@ procedure TBoldObjectListController._ReceiveObjectDeleted( procedure TBoldObjectListController.SubscribeToObjectDeleted(Locator: TBoldObjectLocator); var - ClassList: TBoldObjectList; + SubscriptionSource: TBoldElement; begin if not (OwningObjectList.SubscribeToLocatorsInList or OwningObjectList.SubscribeToObjectsInList) then exit; @@ -418,23 +410,26 @@ procedure TBoldObjectListController.SubscribeToObjectDeleted(Locator: TBoldObjec exit; FSubscriber := TBoldExtendedPassthroughSubscriber.CreateWithExtendedReceive(_ReceiveObjectDeleted); + {$IFNDEF NoBoldClassLists} if Assigned(OwningObjectList.ListElementTypeInfo) then - ClassList := Locator.BoldSystem.Classes[OwningObjectList.ListElementTypeInfo.TopSortedIndex] + SubscriptionSource := Locator.BoldSystem.Classes[OwningObjectList.ListElementTypeInfo.TopSortedIndex] else - ClassList := Locator.BoldSystem.Classes[0]; - + SubscriptionSource := Locator.BoldSystem.Classes[0]; + {$ELSE} + SubscriptionSource := Locator.BoldSystem; + {$ENDIF NoBoldClassLists} if OwningObjectList.SubscribeToLocatorsInList then begin // Subscribe to ClassList instead of System to avoid having all subscriptions on system. // When object is deleted, system sends beObjectDeleted, ClassList receives it and sends beItemDeleted instead if OwningObjectList.SubscribeToObjectsInList then - ClassList.AddSmallSubscription(FSubscriber, [beLocatorDestroying, beObjectDeleted{, beDestroying}]) + SubscriptionSource.AddSmallSubscription(FSubscriber, [beLocatorDestroying, beObjectDeleted{, beDestroying}]) else - ClassList.AddSmallSubscription(FSubscriber, [beLocatorDestroying]); + SubscriptionSource.AddSmallSubscription(FSubscriber, [beLocatorDestroying]); end else if OwningObjectList.SubscribeToObjectsInList then - ClassList.AddSmallSubscription(FSubscriber, [beDestroying, beObjectDeleted]); + SubscriptionSource.AddSmallSubscription(FSubscriber, [beDestroying, beObjectDeleted]); end; procedure TBoldObjectListController.DropSubscriptions; @@ -683,13 +678,11 @@ procedure TBoldClassListController.ReceiveClassEvent(BoldElement: TBoldDomainEle beObjectDeleted: begin Dec(fLoadedObjectCount); - LocatorList.Remove(BoldObject.BoldObjectLocator); if not List.BoldPersistenceStateIsInvalid then begin - // if ClassTypeInfo.Persistent and BoldSystem.BoldPersistent then - // Assert(LocatorList.Includes(BoldObject.BoldObjectLocator)); - if List.HasSubscribers then - List.Publisher.SendEvent(beValueInvalid); + if LocatorList.Remove(BoldObject.BoldObjectLocator) then + if List.HasSubscribers then + List.Publisher.SendEvent(beValueInvalid); end; end; beObjectFetched: @@ -710,7 +703,8 @@ procedure TBoldClassListController.ReceiveClassEvent(BoldElement: TBoldDomainEle Dec(fLoadedObjectCount); if not List.BoldPersistenceStateIsInvalid then begin - SetPersistenceState(bvpsTransient); + if List.BoldPersistenceState <> bvpsTransient then + SetPersistenceState(bvpsTransient); if list.HasSubscribers then List.Publisher.SendEvent(beValueInvalid); end; @@ -837,7 +831,6 @@ procedure TBoldClassListController.SetFromIdList( Locator := BoldSystem.EnsuredLocatorByID[ID]; if not IncludesLocator(Locator) then begin - PreChange; LocatorList.Add(Locator); Changed(beItemAdded, [Locator]); end; @@ -893,7 +886,7 @@ procedure TBoldClassListController.SetFromIdList( for I := 0 to NewList.Count - 1 do InternalAddId(NewList[I]); finally - NewList.Free; + NewList.Free; end; end; @@ -902,8 +895,11 @@ procedure TBoldClassListController.SetPersistenceState( begin with OwningList do begin - BoldPersistenceState := APersistenceState; - SendEvent(beClassListStateChanged); + if BoldPersistenceState <> APersistenceState then + begin + BoldPersistenceState := APersistenceState; + SendEvent(beClassListStateChanged); + end; end; end; diff --git a/Source/BoldSystem.pas b/Source/BoldSystem.pas index f067ea9..aceed30 100644 --- a/Source/BoldSystem.pas +++ b/Source/BoldSystem.pas @@ -2830,7 +2830,7 @@ procedure TBoldSystem.DestroyObject(BoldObject: TBoldObject); // If we got an exception duriung destoy, we might get an half uninitialized BoldObject without Locator next time. if Assigned(aLocator) then //PATCH begin - TBoldClassListController(Classes[aLocator.BoldClassTypeInfo.TopSortedIndex].ObjectListController).ReceiveClassEvent(BoldObject, beLocatorDestroying, []); + TBoldClassListController(Classes[aLocator.BoldClassTypeInfo.TopSortedIndex].ObjectListController).ReceiveClassEvent(BoldObject, beLocatorDestroying, [aLocator]); SendExtendedEvent(beLocatorDestroying, [aLocator]); aLocator.UnloadBoldObject; Locators.Remove(aLocator); @@ -5923,17 +5923,15 @@ procedure TBoldMember.InternalDiscard; {$ENDIF} case BoldPersistenceState of bvpsModified: begin - if not OwningObject.BoldObjectLocator.BoldObjectID.IsStorable then BoldPersistenceState := bvpsCurrent else BoldPersistenceState := bvpsInvalid; - FreeContent; SendEvent(beValueInvalid); end; - bvpsTransient: if not Derived and mutable then - DoSetInitialValue; + bvpsTransient: if not Derived and mutable and not OwningObject.Discarding then + DoSetInitialValue; end; end; end;