Class TGenericStructList
Unit
CastleGenericLists
Declaration
type generic TGenericStructList<T> = class(TFPSList)
Description
Generic list of types that are compared by CompareByte.
This is equivalent to TFPGList, except it doesn't override IndexOf, so your type doesn't need to have a "=" operator built-in inside FPC. When calling IndexOf or Remove, it will simply compare values using CompareByte, this is what TFPSList.IndexOf uses. This way it works to create lists of records, vectors (constant size arrays), old-style TP objects, and also is suitable to create a list of methods (since for methods, the "=" is broken, for Delphi compatibility, see http://bugs.freepascal.org/view.php?id=9228).
We also add some trivial helper methods like Add and L.
Hierarchy
- TFPSList
- TGenericStructList
Overview
Internal Types
Fields
Methods
 |
procedure CopyItem(Src, Dest: Pointer); override; |
 |
procedure Deref(Item: Pointer); override; |
 |
function Get(Index: Integer): T; |
 |
function GetList: PTypeList; |
 |
function ItemPtrCompare(Item1, Item2: Pointer): Integer; |
 |
procedure Put(Index: Integer; const Item: T); |
 |
constructor Create; |
 |
function Add(const Item: T): Integer; |
 |
function Extract(const Item: T): T; |
 |
function First: T; |
 |
function IndexOf(const Item: T): Integer; |
 |
procedure Insert(Index: Integer; const Item: T); |
 |
function Last: T; |
 |
procedure Assign(Source: TGenericStructList); |
 |
function Remove(const Item: T): Integer; |
 |
procedure Sort(Compare: TCompareFunc); |
 |
function L: PT; |
 |
function Add: PT; |
 |
function Ptr(I: Integer): PT; |
Properties
Description
Internal Types
 |
TCompareFunc = function(const Item1, Item2: T): Integer; |
|
Fields
Methods
 |
procedure CopyItem(Src, Dest: Pointer); override; |
|
 |
procedure Deref(Item: Pointer); override; |
|
 |
function Get(Index: Integer): T; |
|
 |
function GetList: PTypeList; |
|
 |
function ItemPtrCompare(Item1, Item2: Pointer): Integer; |
|
 |
procedure Put(Index: Integer; const Item: T); |
|
 |
constructor Create; |
|
 |
function Add(const Item: T): Integer; |
|
 |
function Extract(const Item: T): T; |
|
 |
function First: T; |
|
 |
function IndexOf(const Item: T): Integer; |
|
 |
procedure Insert(Index: Integer; const Item: T); |
|
 |
function Last: T; |
|
 |
function Remove(const Item: T): Integer; |
|
 |
function L: PT; |
Access the list contents directly through a pointer to T structure.
This is exactly the same pointer as List, but the type is different: this points to a single item. This is useful if you have a list of records and you would like to set their fields. This allows to use L[I] instead of Listˆ[I] (only in FPC ObjFpc mode).
See the List description for a more detailed explanation and example.
See also
- List
- Access the list contents directly through a pointer.
|
 |
function Add: PT; |
Increase Count and return pointer to new item. Comfortable and efficient way to add a new item that you want to immediately initialize.
|
 |
function Ptr(I: Integer): PT; |
Pointer to ith item.
|
Properties
 |
property Items[Index:Integer]: T read Get write Put; |
|
 |
property List: PTypeList read GetList; |
Access the list contents directly through a pointer.
This is useful if you have a list of records and you would like to set their fields. This will not work correctly:
type
TMyRecord = record MyField: Integer; end;
TMyRecordList = specialize TGenericStructList<TMyRecord>;
var
MyList: TMyRecordList;
begin
MyList[I].MyField := 123;
(It will not work OK because you would modify only a temporary record returned by the MyList[I] getter.) Instead, setting by
MyList.Listˆ[I].MyField := 123;
will work OK. Or you can use
MyList.L[I].MyField := 123;
See also
- L
- Access the list contents directly through a pointer to T structure.
|
Generated by PasDoc 0.15.0.
|