Advertisement
Borrisholt

Generic TStringList

Jan 11th, 2019
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 1.38 KB | None | 0 0
  1.  
  2. type
  3.   TGenericStringList<T: Class> = class(TStringList)
  4.   private
  5.     function GetObject(Index: Integer): T; reintroduce;
  6.     procedure PutObject(Index: Integer; const Value: T); reintroduce;
  7.   public
  8.     function AddObject(const S: string; AObject: T): Integer; reintroduce;
  9.     function IndexOfObject(AObject: T): Integer; reintroduce;
  10.     procedure InsertObject(Index: Integer; const S: string; AObject: T);
  11.       reintroduce;
  12.     function ToObjectArray: TArray<T>; reintroduce;
  13.     property Objects[Index: Integer]: T read GetObject write PutObject;
  14.  
  15.   end;
  16.  
  17.   { TGenericStringList<T> }
  18.  
  19. function TGenericStringList<T>.AddObject(const S: string; AObject: T): Integer;
  20. begin
  21.   Result := inherited AddObject(S, AObject);
  22. end;
  23.  
  24. function TGenericStringList<T>.GetObject(Index: Integer): T;
  25. begin
  26.   Result := inherited GetObject(Index) as T;
  27. end;
  28.  
  29. function TGenericStringList<T>.IndexOfObject(AObject: T): Integer;
  30. begin
  31.   Result := inherited IndexOfObject(AObject);
  32. end;
  33.  
  34. procedure TGenericStringList<T>.InsertObject(Index: Integer; const S: string;
  35.   AObject: T);
  36. begin
  37.   inherited InsertObject(Index, S, AObject);
  38. end;
  39.  
  40. procedure TGenericStringList<T>.PutObject(Index: Integer; const Value: T);
  41. begin
  42.   inherited PutObject(Index, Value);
  43. end;
  44.  
  45. function TGenericStringList<T>.ToObjectArray: TArray<T>;
  46. begin
  47.   Result := TArray<T>(inherited ToObjectArray);
  48. end;
  49.  
  50. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement