unit SystemVal;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Edit1: TEdit;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

// BeginExample: SystemVal
// Routine: System.Val

// BeginCode
{
This example uses the System Val function to convert a string to
an integer.  Enter an integer in the text edit and then click the
button.  An error will occur if the value entered is not an integer.
}
procedure TForm1.Button1Click(Sender: TObject);
var
  I, Code: Integer;
  mystr: string;
begin
  { Get text from TEdit control }
  mystr := Edit1.Text;
  Val(mystr, 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;
// EndCode
// EndExample: SystemVal
end.
