* Add TList<T>RemoveItem, for delphi compatibility

This commit is contained in:
Michaël Van Canneyt 2024-05-13 14:28:13 +02:00
parent a9b8fb0f05
commit f89cd88ce2

View File

@ -46,11 +46,11 @@ interface
{$IFDEF FPC_DOTTEDUNITS} {$IFDEF FPC_DOTTEDUNITS}
uses uses
System.RtlConsts, System.Classes, System.SysUtils, System.Generics.MemoryExpanders, System.Generics.Defaults, System.RtlConsts, System.Classes, System.SysUtils, System.Generics.MemoryExpanders, System.Generics.Defaults,
System.Generics.Helpers, System.Generics.Strings; System.Generics.Helpers, System.Generics.Strings, System.Types;
{$ELSE FPC_DOTTEDUNITS} {$ELSE FPC_DOTTEDUNITS}
uses uses
RtlConsts, Classes, SysUtils, Generics.MemoryExpanders, Generics.Defaults, RtlConsts, Classes, SysUtils, Generics.MemoryExpanders, Generics.Defaults,
Generics.Helpers, Generics.Strings; Generics.Helpers, Generics.Strings, Types;
{$ENDIF FPC_DOTTEDUNITS} {$ENDIF FPC_DOTTEDUNITS}
{.$define EXTRA_WARNINGS} {.$define EXTRA_WARNINGS}
@ -287,6 +287,7 @@ type
{$ENDIF} {$ENDIF}
function Remove(const AValue: T): SizeInt; function Remove(const AValue: T): SizeInt;
function RemoveItem(const Value: T; Direction: TDirection): SizeInt;
procedure Delete(AIndex: SizeInt); inline; procedure Delete(AIndex: SizeInt); inline;
procedure DeleteRange(AIndex, ACount: SizeInt); procedure DeleteRange(AIndex, ACount: SizeInt);
function ExtractIndex(const AIndex: SizeInt): T; overload; function ExtractIndex(const AIndex: SizeInt): T; overload;
@ -1708,6 +1709,19 @@ begin
DoRemove(Result, cnRemoved); DoRemove(Result, cnRemoved);
end; end;
function TList<T>.RemoveItem(const Value: T; Direction: TDirection): SizeInt;
begin
if Direction=TDirection.FromBeginning then
Result:=Remove(Value)
else
begin
Result:=LastIndexOf(Value);
if Result>=0 then
DoRemove(Result, cnRemoved);
end;
end;
procedure TList<T>.Delete(AIndex: SizeInt); procedure TList<T>.Delete(AIndex: SizeInt);
begin begin
DoRemove(AIndex, cnRemoved); DoRemove(AIndex, cnRemoved);