Link to home
Start Free TrialLog in
Avatar of namcit99
namcit99

asked on

There is not example on document 2005

Dear advisor !

I use Delphi 2005

I want know the example about using VAL function. But there is not example about this function. On document D2005, there is no any examlpe like D6, D7

So i should download document from www.borland.com

Is not example from document D2005 ? Example about Val and str funtion
Avatar of StevenB
StevenB

To the best of my knowledge the Val function works the same in 2005 as it did in previous versions. The example from the D7 help file is:


uses Dialogs;
var

  I, Code: Integer;
begin
  { Get text from TEdit control }
  Val(Edit1.Text, I, Code);
  { Error during conversion to integer? }
  if Code <> 0 then
    MessageDlg('Error at position: ' + IntToStr(Code), mtWarning, [mbOk], 0, mbOk);
  else
    Canvas.TextOut(10, 10, 'Value = ' + IntToStr(I));

end;


Is that what you wanted?
Avatar of namcit99

ASKER


now, I already know to use about Val function. I complaint about document D2005. I want to read example , but nothing.
ASKER CERTIFIED SOLUTION
Avatar of StevenB
StevenB

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial

i am studying using Delphi. so i should use ducument so much when coding. IT is not suitablr for beginner with document D2005. because no example for function.
Firstly, both "Val" and "Str" are procedures not functions.

Secondly, they are both very "old" and both have better modern alternatives.


Really, for "Val" you would be much better off using the "StrToIntDef" or "StrToInt64Def" functions, where you could do something like this;

MyIntVar:=StrToIntDef(MyNumberInStr,0);

with the added bonus of not needing to worry about numeric range limits or invalid characters in "MyNumberInStr" raising exceptions.


and for "Str" you would be better off using the "Format" function, like this;

MyNumberInStr:=Format(MyFormatStr,MyIntVar);

the "Format" function can deal with, pretty much, any kind of variable(s) in many ways, the "Format" function is very powerful and very flexible.


Cheers,

David.
...although Val has the added functionality of returning the offending character position in the case of failure, which sets it apart from StrToIntDef or StrToInt.

I consider on your idea