Rus Articles Journal

Lesson of programming. The 2nd part

I so, dear friends, last time we finished the fact that collected the console &ndash program; calculator. This time, we should write more difficult thing, namely the dialogue program. It is many times easier, but also reefs will meet here.

we Will start. First of all we will begin to collect visual part, namely: let`s fill a form with buttons, inscriptions, fields for input of the text and a context menu. At once you will prepare, the lesson will be longer and difficult, but we will take as they say “occasion by the forelock“ and it is more difficult to take work.

Start the program, further pass into the File menu - new - application. Before you there will be a new form in which we also will begin to work. Let`s add on it the button (Tbutton), 2 fields for input of the text (TEdit), and an inscription (TLabel). So far these components will be enough for us. Place from as shown in drawing (fig. 1).

after that we will start writing of a code of the program. We click two times on the button (Button1). we will see the following code:

of procedure TForm1. Button1Click (Sender: TObject);

of begin

end; to

After the line Begin, we write the following code:

of label1. caption: =

of Inttostr (strtoint (Edit1. Text) +strtoint (Edit2. text));

Now, I will try to explain that every line means.

of IntToStr is the translation of number (Int - integer), at line.

of StrToInt - Inverse function. That is from a line in number.

That is, we can present this line in the form:

Nadpis1. capture: =

From number at line (from a line in number (pole1. the text) + from a line in number (pole2. text)); to

Of course, it only for the best understanding, it is impossible to write so a code.

what we wrote now is the handler of pressing the button. Now, when we will click on the button, the program will count two numbers in fields. But you remember that numbers can be in the range ___________ as have the integer type. Of course it is possible to give him with functions of subtraction, division and multiplication, but you make it as it is not difficult, it is just necessary to replace the sign “+“ with another. Division - “/“, Multiplication - “*“ and subtraction - “ - “, without quotes. As a result at you the calculator which puts will turn out, will read, divides and multiplies integers.

dealt With writing of the program, now, we will pass to creation of the menu. Such menu is almost in each program respecting itself, whether it be the elementary calculator or a difficult text editor. Creation of such menu, will take at most 5 minutes. by

to create it, it is necessary to choose a component (tMainmenu). this component not visual, so, its placement will not affect by sight programs. Now click two times on a component, the designer of the menu will open. To create point we click on a free menu item and we write its name. Everything as soon as you create you can close it. Create such points:

“File“ - To Put, subtract, increase, divide, an exit.

“Reference“ - About the program.

Will turn out something like it:

Click on the About the Program point, the editor of a code will open. Now enter:

of Form2. showmodal; I Explain

that such “showmodal“. If to enter instead of it just show, then a window which will open