Essa calculadora básica pode ser feita tanto no Delphi como no Lazarus:
Componentes necessários:
Código-Fonte:
Componentes necessários:
Label1 = NÚMERO1
Label2 = NÚMERO2
Label3 = RESULTADO
Button1 = ADIÇÃO
Button2 = DIVISÃO
Button3 = MULTIPLICAÇÃO
Button4 = SUBTRAÇÃO
Button5 = APAGAR
Button6 = SAIR
Código-Fonte:
- Código:
unit Ucalculadora;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, StdCtrls,
Buttons;
type
{ TForm1 }
TForm1 = class(TForm)
ADICAO: TButton;
SUBTRACAO: TButton;
DIVISAO: TButton;
MULTIPLICACAO: TButton;
APAGAR: TButton;
SAIR: TButton;
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
procedure ADICAOClick(Sender: TObject);
procedure APAGARClick(Sender: TObject);
procedure DIVISAOClick(Sender: TObject);
procedure MULTIPLICACAOClick(Sender: TObject);
procedure SAIRClick(Sender: TObject);
procedure SUBTRACAOClick(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
end;
var
Form1: TForm1;
implementation
{ TForm1 }
procedure TForm1.ADICAOClick(Sender: TObject);
var n1,n2,calculo:real;
begin
n1:=StrToFloat(Edit1.text);
n2:=StrToFloat(Edit2.text);
calculo:=n1+n2;
Edit3.text:=FloatToStr(calculo);
end;
procedure TForm1.APAGARClick(Sender: TObject);
begin
Edit1.text:='';
Edit2.text:='';
Edit3.text:='';
end;
procedure TForm1.DIVISAOClick(Sender: TObject);
var
n1,n2,calculo:real;
begin
n1:=StrToFloat(Edit1.text);
n2:=StrToFloat(Edit2.text);
calculo:=n1/n2;
Edit3.text:=FloatToStr(calculo);
end;
procedure TForm1.MULTIPLICACAOClick(Sender: TObject);
var
n1,n2,calculo:real;
begin
n1:=StrToFloat(Edit1.text);
n2:=StrToFloat(Edit2.text);
calculo:=n1*n2;
Edit3.text:=FloatToStr(calculo);
end;
procedure TForm1.SAIRClick(Sender: TObject);
begin
Form1.Close;
end;
procedure TForm1.SUBTRACAOClick(Sender: TObject);
var
n1,n2,calculo:real;
begin
n1:=StrToFloat(Edit1.text);
n2:=StrToFloat(Edit2.text);
calculo:=n1-n2;
Edit3.text:=FloatToStr(calculo);
end;
initialization
{$I ucalculadora.lrs}
end.
Créditos: sl@ckw@re