Changeset 221 for Generics


Ignore:
Timestamp:
Mar 28, 2011, 9:22:05 AM (14 years ago)
Author:
george
Message:
  • Added: AddNew and InsertNew methods can accept precreated object reference.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • Generics/TemplateGenerics/Generic/GenericListObject.inc

    r220 r221  
    1717  public
    1818    OwnsObjects: Boolean;
    19     function AddNew: TGListItem;
    20     function AddInsertNew(Index: TGListIndex): TGListItem;
     19    function AddNew(NewObject: TGListItem = nil): TGListItem;
     20    function AddInsertNew(Index: TGListIndex; NewObject: TGListItem = nil): TGListItem;
    2121    procedure Delete(Index: TGListObjectIndex); override;
    2222    procedure Clear; override;
     
    5151{ TGListObject }
    5252
    53 function TGListObject.AddNew: TGListItem;
     53function TGListObject.AddNew(NewObject: TGListItem = nil): TGListItem;
    5454begin
    55   Result := TGListItem.Create;
     55  if Assigned(NewObject) then Result := NewObject
     56    else Result := TGListItem.Create;
    5657  Add(Result);
    5758end;
    5859
    59 function TGListObject.AddInsertNew(Index: TGListIndex): TGListItem;
     60function TGListObject.AddInsertNew(Index: TGListIndex;
     61  NewObject: TGListItem = nil): TGListItem;
    6062begin
    61   Result := TGListItem.Create;
     63  if Assigned(NewObject) then Result := NewObject
     64    else Result := TGListItem.Create;
    6265  Insert(Index, Result);
    6366end;
Note: See TracChangeset for help on using the changeset viewer.