Das ist doch mal eine Möglichkeit einen Enumerator zu verwenden:
Delphi-Quellcode:
type
TNumericEnumerator = record
constructor Create(AList: TStrings);
private
FIndex: Integer;
FList: TStrings;
function Accept(const AItem: string): Boolean; inline;
function GetCurrent: string; inline;
public
function MoveNext: Boolean; inline;
property Current: string read GetCurrent;
function GetEnumerator: TNumericEnumerator;
end;
{ TNumericEnumerator }
function TNumericEnumerator.Accept(const AItem: string): Boolean;
const
NUMBERS = ['0'..'9'];
var
i: Integer;
begin
for i := 1 to Length(AItem) do
begin
if not (AItem[i] in NUMBERS) then
begin
Result := False;
Exit;
end;
end;
Result := True;
end;
constructor TNumericEnumerator.Create(AList: TStrings);
begin
FList := AList;
end;
function TNumericEnumerator.GetCurrent: string;
begin
Result := FList[FIndex];
end;
function TNumericEnumerator.GetEnumerator: TNumericEnumerator;
begin
Result := Self;
end;
function TNumericEnumerator.MoveNext: Boolean;
var
i: Integer;
begin
for i := FIndex + 1 to FList.Count - 1 do
begin
if Accept(FList[i]) then
begin
FIndex := i;
Result := True;
Exit; // ==>
end;
end;
Result := False;
end;
{ Anwendung}
procedure TuWas(AList: TStrings);
var
s: string;
begin
for s in TNumericEnumerator.Create(AList) do
TuWasMitNumeric(s);
end;