Changeset 7 for os/trunk/Xvcl
- Timestamp:
- Jun 2, 2013, 6:59:07 PM (12 years ago)
- Location:
- os/trunk/Xvcl
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
os/trunk/Xvcl/Xvcl.Classes.pas
r5 r7 2 2 3 3 interface 4 5 uses 6 Xvcl.Generics; 4 7 5 8 type … … 51 54 FOwner: TComponent; 52 55 FName: string; 56 FComponents: TObjectList<TComponent>; 57 procedure SetOwner(const Value: TComponent); 53 58 public 54 59 constructor Create; virtual; 55 property Owner: TComponent read FOwner write FOwner; 60 destructor Destroy; override; 61 property Components: TObjectList<TComponent> read FComponents; 62 property Owner: TComponent read FOwner write SetOwner; 56 63 property Name: string read FName write FName; 57 64 end; … … 161 168 constructor TComponent.Create; 162 169 begin 170 FComponents := TObjectList<TComponent>.Create; 171 end; 172 173 destructor TComponent.Destroy; 174 begin 175 FComponents.Destroy; 176 inherited; 177 end; 178 179 procedure TComponent.SetOwner(const Value: TComponent); 180 begin 181 if Value = FOwner then Exit; 182 if not Assigned(Value) then FOwner.Components.Remove(Self); 183 FOwner := Value; 184 if Assigned(Value) then FOwner.Components.Add(Self); 163 185 end; 164 186 … … 181 203 Self.Y := Y; 182 204 end; 183 184 205 185 206 function TPoint.IsZero: Boolean; -
os/trunk/Xvcl/Xvcl.Generics.pas
r5 r7 33 33 function Compare(Item1, Item2: T): Integer; 34 34 procedure Exchange(Index1, Index2: Integer); 35 procedure Clear; 35 36 property Count: Integer read FCount write SetCount; 36 37 property Items[Index: Integer]: T read GetItem write SetItem; default; 38 end; 39 40 TObjectList<T: class> = class(TList<T>) 41 OwnsObjects: Boolean; 42 constructor Create; virtual; 43 destructor Destroy; override; 37 44 end; 38 45 … … 61 68 FItems[Count - 1] := Item; 62 69 Result := Count - 1; 70 end; 71 72 procedure TList<T>.Clear; 73 begin 74 Count := 0; 63 75 end; 64 76 … … 149 161 end; 150 162 163 { TObjectList<T> } 164 165 constructor TObjectList<T>.Create; 166 begin 167 OwnsObjects := True; 168 end; 169 170 destructor TObjectList<T>.Destroy; 171 var 172 I: Integer; 173 begin 174 if OwnsObjects then 175 for I := 0 to Count - 1 do 176 TObject(FItems[I]).Destroy; 177 Clear; 178 inherited; 179 end; 180 151 181 end.
Note:
See TracChangeset
for help on using the changeset viewer.