Halaman

Pengikut

Jumat, 29 April 2011

Make addition, substraction, multiplication and division Delphi program

To make addition, substraction, multiplication and division Delphi program is not difficult, if we have will to do it. OK, we will start to examine. First, make worksheet form like this below:

Basically, default name of edit text on right side of First number caption is edit1, erdit text on right side of Second number caption is edit2 and edit text on right side of Result is edit3. On this chance, we will change the name, we change edit1 with input1, edit2 with input2 and edit3 with output. Actually, no problem if we use default name without change them, however only to explain that edit1 is function as input1, edit2 is function as input2 and edit3 is function as output.

Now, we will start to write its syntax code. Depend on you, will which button start from between 4 button will be used. On this chance, we will just start from +(plus) button, then -(minus) button, then x(times) button and the last :(divided) button.

Don’t forget to save your file, at this chance we will save with name additon_and_multiplication, no problem with another name, only influence on syntax code or unit name, likely Delphi don’t allow the name with name which use space.

  1. Click on worksheet form, then double click on plus button, so that will show form code, and your cursor is between begin and end; and write there code below:
    a:=strtofloat(input1.text);
    b:=strtofloat(input2.text);
    c:=a+b;
    output.text:=floattostr(c);

    and formula for plus button have finished.
  2. Click again worksheet form, then double click on minus button, so that will show form code and your cursor still is between begin and end; and write there code below:
    a:=strtofloat(input1.text);
    b:=strtofloat(input2.text);
    c:=a-b;
    output.text:=floattostr(c);

  3. Click again worksheet form, then double click on times button, so that will show form code, and your cursor is between begin and end; and write there code below:
    a:=strtofloat(input1.text);
    b:=strtofloat(input2.text);
    c:=a*b;
    output.text:=floattostr(c);

  4. Click again worksheet form, then double click on divided button, so that will show form code, and your cursor is between begin and end; and write there code below:
    a:=strtofloat(input1.text);
    b:=strtofloat(input2.text);
    c:=a/b;
    output.text:=floattostr(c);

  5. Then, this time to declaration variables are used, are a, b and c variable. Move up your cursor until you find this code below:
    var
    Form1: TForm1;
    Implementation

  6. Then write code between Tform1; and Implementation.
    Ini kodenya:
    a,b,c:real;
  7. so that more complete code be like this:
    var
    Form1: TForm1;
    a,b,c:real;
    implementation

    Now try to click Run to run program and please test, like picture below:


That is sign of success to make a simple program with use Delphi, for friends is understandless, please ask to sahabat, if sahabat can, will help others
So, completely program syntax of this program is:

unit addition_and_multiplication;

interface

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

type
TForm1 = class(TForm)
input1: TEdit;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
input2: TEdit;
Label4: TLabel;
output: TEdit;
Label5: TLabel;
Button1: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
a,b,c:real;
implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
a:=strtofloat(input1.text);
b:=strtofloat(input2.text);
c:=a+b;
output.text:=floattostr(c);
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
a:=strtofloat(input1.Text);
b:=strtofloat(input2.text);
c:=a-b;
output.Text:=floattostr(c);
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
a:=strtofloat(input1.Text);
b:=strtofloat(input2.Text);
c:=a*b;
output.Text:=floattostr(c);
end;

procedure TForm1.Button4Click(Sender: TObject);
begin
a:=strtofloat(input1.text);
b:=strtofloat(input2.text);
c:=a/b;
output.text:=floattostr(c);
end;

end.


For friends who want to see example of application program is created by syntax above on Delphi can download it here and who want to download microsoft word file (.doc file) can download it here


All of truth come from God and faults are from me

Comments :

0 komentar to “Make addition, substraction, multiplication and division Delphi program”

Posting Komentar

 

Copyright © 2009 by coretan sahabat