From: Steven M. <sr...@us...> - 2005-11-24 23:11:50
|
Update of /cvsroot/instantobjects/Source/Core In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18047 Modified Files: InstantAccessors.pas Log Message: 1. TInstantAccessor and TInstantObjectAccessor classes were modified to make TInstantObjectAccessor use a TObjectList of TInstantObjectReferences for the View list. The TInstantObjectReferences have their OwnsInstance properties set to true so that the view object instances are not destroyed before the view list is freed. Index: InstantAccessors.pas =================================================================== RCS file: /cvsroot/instantobjects/Source/Core/InstantAccessors.pas,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** InstantAccessors.pas 23 Oct 2005 23:13:26 -0000 1.5 --- InstantAccessors.pas 24 Nov 2005 23:11:42 -0000 1.6 *************** *** 45,53 **** --- 45,57 ---- TInstantObjectAccessor = class(TInstantAccessor) private + function CreateObjectReference(AObject: TObject): TInstantObjectReference; function GetContainer: TInstantContainer; function GetSubject: TInstantObject; protected function GetConnector: TInstantConnector; override; + function GetObjectCount: Integer; override; + function GetView: TList; override; function InternalAddObject(AObject: TObject): Integer; override; + function InternalAddToView(AObject: TObject): Integer; override; procedure InternalApplyChanges; override; procedure InternalClear; override; *************** *** 55,62 **** --- 59,71 ---- function InternalGetObjects(Index: Integer): TObject; override; function InternalGetObjectCount: Integer; override; + function InternalGetViewObjects(Index: Integer): TObject; override; function InternalIndexOfInstance(Instance: Pointer): Integer; override; function InternalIndexOfObject(AObject: TObject): Integer; override; + procedure InternalInsertInView(Index: Integer; AObject: TObject); override; function InternalInsertObject(Index: Integer; AObject: TObject): Integer; override; + function InternalRemoveFromView(AObject: TObject): Integer; override; function InternalRemoveObject(AObject: TObject): Integer; override; + function InternalViewIndexOfInstance(Instance: Pointer): Integer; override; + function InternalViewIndexOfObject(AObject: TObject): Integer; override; property Container: TInstantContainer read GetContainer; public *************** *** 104,108 **** uses ! SysUtils; { TInstantObjectAccessor } --- 113,117 ---- uses ! SysUtils, Contnrs, InstantClasses, InstantConsts; { TInstantObjectAccessor } *************** *** 122,125 **** --- 131,144 ---- end; + function TInstantObjectAccessor.CreateObjectReference(AObject: TObject): + TInstantObjectReference; + begin + if AObject is TInstantObject then + Result := TInstantObjectReference.Create(TInstantObject(AObject), True) + else + raise EInstantError.CreateFmt(SInvalidClass, + [AObject.ClassName, InternalGetObjectClassName]); + end; + function TInstantObjectAccessor.GetConnector: TInstantConnector; begin *************** *** 132,135 **** --- 151,161 ---- end; + function TInstantObjectAccessor.GetObjectCount: Integer; + begin + if Altered then + Result := View.Count + else + Result := InternalObjectCount; + end; function TInstantObjectAccessor.GetSubject: TInstantObject; begin *************** *** 137,140 **** --- 163,186 ---- end; + function TInstantObjectAccessor.GetView: TList; + var + I: Integer; + Continue:Boolean; + begin + if not Assigned(FView) then + begin + Continue:=True; + FView := TObjectList.Create; + FView.Capacity := InternalObjectCount; + for I := 0 to Pred(InternalObjectCount) do + begin + DoProgress(InternalObjects[I], I+1, Continue); + if not Continue then Break; + AddToView(InternalObjects[I]); + end; + end; + Result := FView; + end; + function TInstantObjectAccessor.InternalAddObject(AObject: TObject): Integer; begin *************** *** 145,148 **** --- 191,199 ---- end; + function TInstantObjectAccessor.InternalAddToView(AObject: TObject): Integer; + begin + Result := View.Add(CreateObjectReference(AObject)); + end; + procedure TInstantObjectAccessor.InternalApplyChanges; begin *************** *** 181,184 **** --- 232,240 ---- end; + function TInstantObjectAccessor.InternalGetViewObjects(Index: Integer): TObject; + begin + Result := TInstantObjectReference(View[Index]).Dereference(Connector); + end; + function TInstantObjectAccessor.InternalIndexOfInstance( Instance: Pointer): Integer; *************** *** 199,202 **** --- 255,264 ---- end; + procedure TInstantObjectAccessor.InternalInsertInView(Index: Integer; AObject: + TObject); + begin + View.Insert(Index, CreateObjectReference(AObject)); + end; + function TInstantObjectAccessor.InternalInsertObject(Index: Integer; AObject: TObject): Integer; *************** *** 210,213 **** --- 272,283 ---- end; + function TInstantObjectAccessor.InternalRemoveFromView(AObject: TObject): + Integer; + begin + Result := InternalViewIndexOfObject(AObject); + if Result > -1 then + View.Delete(Result); + end; + function TInstantObjectAccessor.InternalRemoveObject( AObject: TObject): Integer; *************** *** 219,222 **** --- 289,312 ---- end; + function TInstantObjectAccessor.InternalViewIndexOfInstance(Instance: Pointer): + Integer; + begin + Result := InternalViewIndexOfObject(Instance); + end; + + function TInstantObjectAccessor.InternalViewIndexOfObject(AObject: TObject): + Integer; + var + Ref: TInstantObjectReference; + begin + for Result := 0 to Pred(View.Count) do + begin + Ref := TInstantObjectReference(View[Result]); + if Ref.Equals(AObject as TInstantObject) then + Exit; + end; + Result := -1; + end; + class function TInstantObjectAccessor.SubjectClass: TClass; begin |