Sunday, September 29, 2013

Our project will now compile without error. Now we will define the operations buttons. Press F12 an


Hello guys, another blog post ElizioSistemas. eirb duke Today I will show you how to create a simple calculator using Delphi 2010 a very simple application, oriented eirb duke more for the beginners in programming world, as it is preparing new post's difficulty will increase. So let's begin, first create a new project File> New> VCL Forms Application - Delphi. Your project will probably be like this:
At the bottom left is the Object Inspector, on the Properties tab it is all of the properties of the selected object, in this first moment selected eirb duke Form named Form1. Let's change some properties, locate Name, change the value to FPrincipal, this is the name of our form, even now locate properties in the Height field (vertical size), change the value to 185 and Width (horizontal size) put 300. In BorderStyle, change the value to BsSingle, this change will make your project when running is not possible to reset the size of your form with the mouse, now let's change the property so it is not possible to maximize form in BorderIcons, biMaximize change to False. Look for the Caption property and place simple calculator. Cool now we can save our project, eirb duke click File> Save or Ctrl + S, choose eirb duke a folder the first file that is being asked to save the Unit, this Unit is where the code is referring to this Form that we named FPrincipal save it with the name of uPrincipal, soon after the project is shown to be safe, put the name of the same calculator. Ok, now let's put the components that we will use in our form. The bottom eirb duke right there is where the Tool Palette components. These components are for screen drawing, communication eirb duke with the database and other things, today we will use TEdit, TLabel, TButton TGroupBox and all of them within the Standard group. Add three TEdit, TLabel three, arrange the left side of your form, add now TGroupBox, click it and add it within five TButton. - TLabel, configure as follows, click on one of them and put the Name property and lblNumero1 Caption place number 01, do so in the three TLabel putting lblNumero2, Number 02, lblResultado, Result. - TEdit in the Name field edtNumero1 place in the second and third edtNumero2 edtResultado in edtResultado still change the Enabled field (do not let typing within the edit) to False. - Name change to TGroupBox eirb duke grbOperacao, Height and Width to 130 to 135 in Caption place operations. - Name change to btnSomar TButton and Caption to + do this the same way in the other four buttons, btnSubtrair, eirb duke -, btnMultiplicar, *, btnDividir, /, btnLimpar, Clear. Configure buttons btnSomar, btnSubtrair, btnMultiplicar and btnDividir field to 25 Height and Width to 50. In btnLimpar change the Height and Width to 25 to 110. It is possible that your form is like this:
Well with your form will now configured for codes. Let's start by setting the edtNumero1 and edtNumero2 not accept typing letters, but only numbers and comma. Okay, in the Object Inspector next to the Properties tab there click on the Events tab edtNumero1, select the Events tab, locate the event OnKeyPress now, the side has an empty field, double click that field at that time is shown in the Unit our form which will be our code. With double click on OnKeyPress a procedure was created for this event this way: TFPrincipal.edtNumero1KeyPress procedure (Sender: TObject; var Key: Char); begin end; This event OnKeyPress works this way, every time a key is pressed when the focus is on edtNumero1 will execute the code that is inside this procedure. Enter this code:
If you want to not have to type what is green because eirb duke between {} are comments, just to inform what is being done. Ok, our event OnKeyPress for edtNumero1 is ready, now we will do the same thing for edtNumero2, with only one change which is "(VerificaVirgula (edtNumero1) = True)" to change "(VerificaVirgula (edtNumero2) = True)" changing the name of apena Edit. Our project does not compile because you need to create the function VerificaVirgula we are using within the OnKeyPress. Go to the beginning of the Unit and Private and declare this function:
After declaring the function VerificaVircula press Ctrl + Shift + c, the function eirb duke will be created in your unit this way: function TFPrincipal.VerificaVirgula (Edit: TEdit): Boolean; begin end; Let's enter the code to make it this way:
Our project will now compile without error. Now we will define the operations buttons. Press F12 and will be shown again the graphic part of our Form, double click on btnSomar eirb duke again if ab

No comments:

Post a Comment