...überprüfen ob ein String nur aus Zahlen besteht?
Autor: Simon Grossenbacher
{1.}
function IsStrANumber(const S: string): Boolean;
var
P: PChar;
begin
P := PChar(S);
Result := False;
while P^ <> #0 do
begin
if not (P^ in ['0'..'9']) then Exit;
Inc(P);
end;
Result := True;
end;
{2.}
function IsStrANumber(const S: string): Boolean;
begin
Result := True;
try
StrToInt(S);
except
Result := False;
end;
end;
// Example:
procedure TForm1.Button1Click(Sender: TObject);
begin
if IsStrANumber(edit1.Text) = True then
ShowMessage('String contains only numbers!');
end;
printed from
www.swissdelphicenter.ch
developers knowledge base