Re: calculator



p.shakerifar@xxxxxxxxx wrote:

please say me how can I write a calculator program in delphi?
some thing that works like computers calculator

Minimalistic example:
Drop an TEdit and two Buttons on a Form.
Set the TEdits text to empty.
Give the first button the caption "1" and the
second one the caption "+".
Double click the form and both buttons to create event handlers.

----------------------------------------------------------------
Code:
unit Unit1;

interface

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

type
TForm1 = class(TForm)
Edit1: TEdit;
Button1: TButton;
Button2: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private-Deklarationen }
number:extended;
displaying:boolean;
public
{ Public-Deklarationen }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
number:=0;
displaying:=false;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
if Displaying then
Edit1.text:='';
Edit1.text:=Edit1.text+'1';
Displaying:=False;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
number:=number+StrToFloat(Edit1.text);
Edit1.Text:=FloatToStr(Number);
Displaying:=True;
end;

end.
-----------------------------------------

This will create a calculator that allows you to add
sequences of "1"s.
You should be easily be able to add Input keys for other
numbers and operators from here.






.


Quantcast