To convert a string into an integer you can use the StrToInt(MyString: String) function. If you pass it 'xaslk' as MyString you will get an exception informing you that 'xaslk' is not an integer-value. It would be pretty annoying if your program crashed every time, the user passes an invalid value. To catch the exception yourself use:
procedure Button1Click(Sender: TObject);
begin
try
strtotint('xaslk');
except
showmessage('You did not pass a valid integer value. Please try again.');
exit;
finally
//...
end;
end;
Everything behind except is only executed if an exception occurs. All the
statements behind finally are always executed. You should free resources
here etc.
You can control the events of the components in you form on the event-tab of the object-inspector. Select a button and look at its events. You will find that there are surprisingly many. OnClick is by far most important. Please refer to the Delphi help-file for a describtion of the events.
To assign an action to an event, simply double-click on the empty field to the right of the event's name. Delphi will open a procedure for you with the correct parameters and assign it to the event. The name of the procedure is made up of the component's name and the event (without the "on"). For Button1 and OnClick this would be Button1Click.
To assign a procedure to an event manually simply use:
Component.OnEvent:= MyEventprocedure;Where Component.OnEvent is an event-property (Button1.OnClick for example) and MyEventprocedure is the procedure to be assigned to the event. Be aware that the procedure needs to have to correct arguments, in this case it would look like this:
procedure MyEventprocedure(Sender: TObject);
For other events this might be a lot different. The easiest way to find out what arguments an event-procedure needs is to double-click on the event and look at the template that Delphi makes for you.
Please e-mail me with any comments!
© 27.12.96 Sebastian
Boßung