Class helper is a great idea here. To make it more widely applicable, you must choose to associate the helper with the least derived class that the helper can apply to. In this case, it means TStrings.
, TStrings, . TStrings, , ..
, . :
type
TStringsHelper = class helper for TStrings
public
procedure RemoveIf(const Predicate: TPredicate<string>);
procedure RemoveEmptyStrings;
end;
procedure TStringsHelper.RemoveIf(const Predicate: TPredicate<string>);
var
Index: Integer;
begin
for Index := Count-1 downto 0 do
if Predicate(Self[Index]) then
Delete(Index);
end;
procedure TStringsHelper.RemoveEmptyStrings;
begin
RemoveIf(
function(Item: string): Boolean
begin
Result := Item.IsEmpty;
end;
);
end;
TStrings . . :
AddFmt, .AddStrings, .- A
Contains, IndexOf(...)<>-1 . - A
Data[], NativeInt AddData, Objects[]. TObject NativeInt.
, , .