Ignore:
Timestamp:
Apr 3, 2012, 7:35:26 AM (12 years ago)
Author:
chronos
Message:
  • Added: Update locking support for TGList.
  • Modified: Enhanced TGStream methods.
File:
1 edited

Legend:

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

    r312 r342  
    2424    FItems: array of TGListItem;
    2525    FCount: TGListIndex;
     26    FUpdateCount: NativeInt;
     27    FOnUpdate: TNotifyEvent;
    2628    function Get(Index: TGListIndex): TGListItem;
    2729    function GetCapacity: TGListIndex;
     
    7274    procedure Sort(Compare: TGListSortCompare);
    7375    procedure SetArray(Values: array of TGListItem);
     76    procedure BeginUpdate;
     77    procedure EndUpdate;
     78    procedure Update;
    7479    property Count: TGListIndex read FCount write SetCount;
    7580    property Capacity: TGListIndex read GetCapacity write SetCapacity;
     
    107112    I := I + 1;
    108113  end;
     114  Update;
    109115end;
    110116
     
    118124    I := I + 1;
    119125  end;
     126  Update;
    120127end;
    121128
     
    130137    I := I + 1;
    131138  end;
     139  Update;
    132140end;
    133141
     
    248256    I := I + 1;
    249257  end;
     258  Update;
    250259end;
    251260
     
    294303  InsertCount(Index, 1);
    295304  FItems[Index] := Item;
     305  Update;
    296306end;
    297307
     
    319329  if Index < FCount then
    320330    System.Move(FItems[Index], FItems[Index + ACount], (FCount - ACount - Index) * SizeOf(TGListItem));
     331  Update;
    321332end;
    322333
     
    409420  //Delete(CurIndex);
    410421  //Insert(NewIndex, Temp);
     422  Update;
    411423end;
    412424
     
    434446    end;
    435447  end;
     448  Update;
    436449end;
    437450
     
    469482    I := I + 1;
    470483  end;
     484  Update;
    471485end;
    472486
     
    475489  if FCount > 1 then
    476490    QuickSort(0, FCount - 1, Compare);
     491  Update;
    477492end;
    478493
     
    486501    I := I + 1;
    487502  end;
     503  Update;
    488504end;
    489505
     
    498514    I := I + 1;
    499515  end;
     516end;
     517
     518procedure TGList.BeginUpdate;
     519begin
     520  Inc(FUpdateCount);
     521end;
     522
     523procedure TGList.EndUpdate;
     524begin
     525  Dec(FUpdateCount);
     526  Update;
     527end;
     528
     529procedure TGList.Update;
     530begin
     531  if Assigned(FOnUpdate) and (FUpdateCount = 0) then FOnUpdate(Self);
    500532end;
    501533
     
    530562  Result := FCount - 1;
    531563  FItems[Result] := Item;
     564  Update;
    532565end;
    533566
     
    545578    J := J + 1;
    546579  end;
     580  Update;
    547581end;
    548582
     
    560594    J := J + 1;
    561595  end;
     596  Update;
    562597end;
    563598
     
    575610  System.Move(FItems[Index + 1], FItems[Index], (FCount - Index) * SizeOf(TGListItem));
    576611  SetCapacityOptimized(Capacity - 1);
     612  Update;
    577613end;
    578614
     
    586622    I := I + 1;
    587623  end;
     624  Update;
    588625end;
    589626
     
    597634    I := I + 1;
    598635  end;
     636  Update;
    599637end;
    600638
     
    610648  FItems[Index1] := FItems[Index2];
    611649  FItems[Index2] := Temp;
     650  Update;
    612651end;
    613652
Note: See TracChangeset for help on using the changeset viewer.