Kylix
Tips

NEW TIPS
Database (112)
Files (567)
Forms (583)
Graphic (520)
IDE (439)
Indy (410)
Internet / LAN (575)
IntraWeb (432)
Kylix (426)
Math (546)
Misc (565)
Multimedia (473)
Objects/
ActiveX (486)

OpenTools API (423)
Printing (428)
Strings (560)
System (705)
VCL (575)

Search Tip
Top15
Add new Tip

Forum

...validate a float number?
Author: Thomas Stutz
[ Print tip ]    

Tip Rating (0):  
     



function StrIsReal(AString: string): Boolean;
var
  
I: Extended;
  Code: Integer;
begin
  
Val(AString, I, Code);
  Result := Code = 0;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  
Edit1.Text := '123.222';
  if StrIsReal(Edit1.Text) then
    
ShowMessage('Valid float number! Gültige Gleitkommazahl!');
end;


// In Delphi 6, there is a TryStrToFloat function
// In Delphi6 gibt's auch eine TryStrToFloat Funktion

procedure TForm1.Button1Click(Sender: TObject);
var
  
s: string;
  f: double;
begin
  
s := '123.222';
  if TryStrToFloat(s, f) then
    
ShowMessage('Ok!')
  else
    
ShowMessage('No valid float number!');
end;

Rate this tip:

poor
very good


Copyright © Torry's Delphi Pages Torry's Delphi Pages Maintained by Simon Grossenbacher Notes? Comments? Feel free to send... Copyright © 1996-2001