I use Delphi5 prof.
I want to enter a value to an integer variable via a form at runtime.
(Like in grandpa's Turbo Pascal: var i: integer; begin readln(i); ... )
Question 1: Can I do this directly or do I have to use the StrToInt function?
For the latter, Delphi Help provides an example for IntToStr. (which uses both functions):
(The // line was supplemented by me)
This code doesn’t work, entering an(alpha-)string instead of an integers into an edit box causes an error break, returns to the project editor and shows the error message
“Project p.exe raised exception class EConvertError with message ‘’[string]’ is not a valid integer value’. Process stopped. Use Step or Run to continue.”
The program does set forth after the breakpoint (ShowMessage...).
Setting (xxx) to EConverError and (yyy) to [blank] was no remedy, nor were other experiments.
Question 2. Can I avoid this errorbreak?
I want to enter a value to an integer variable via a form at runtime.
(Like in grandpa's Turbo Pascal: var i: integer; begin readln(i); ... )
Question 1: Can I do this directly or do I have to use the StrToInt function?
For the latter, Delphi Help provides an example for IntToStr. (which uses both functions):
Code:
procedure TForm1.Button1Click(Sender: TObject);
begin
try
Label1.Caption := IntToStr(StrToInt(Edit1.Text) * StrToInt(Edit2.Text));
except
// on (xxx) do (yyy);
ShowMessage('You must specify integer values. Please try again.');
end;
end;
This code doesn’t work, entering an(alpha-)string instead of an integers into an edit box causes an error break, returns to the project editor and shows the error message
“Project p.exe raised exception class EConvertError with message ‘’[string]’ is not a valid integer value’. Process stopped. Use Step or Run to continue.”
The program does set forth after the breakpoint (ShowMessage...).
Setting (xxx) to EConverError and (yyy) to [blank] was no remedy, nor were other experiments.
Question 2. Can I avoid this errorbreak?