Código fonte calculadora
unit unitCalculator;{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
Menus, ComCtrls, ExtCtrls, unitHistorico;
type
{ TCalculadoraLe }
TCalculadoraLe = class(TForm)
Button1: TButton;
Button0: TButton;
ButtonSalvar: TButton;
ButtonIgual: TButton;
ButtonVirg: TButton;
ButtonLimpar: TButton;
ButtonMult: TButton;
ButtonDiv: TButton;
ButtonAdd: TButton;
ButtonSub: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
Button5: TButton;
Button6: TButton;
Button7: TButton;
Button8: TButton;
Button9: TButton;
MainMenu1: TMainMenu;
MenuItemArquivo: TMenuItem;
BotaoSair: TMenuItem;
MenuItemAjuda: TMenuItem;
BotaoAjudaAutor: TMenuItem;
MenuItemHist: TMenuItem;
StatusBar1: TStatusBar;
TimerHora: TTimer;
Visor: TLabel;
procedure BotaoAjudaAutorClick(Sender: TObject);
procedure BotaoSairClick(Sender: TObject);
procedure Button0Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure Button5Click(Sender: TObject);
procedure Button6Click(Sender: TObject);
procedure Button7Click(Sender: TObject);
procedure Button8Click(Sender: TObject);
procedure Button9Click(Sender: TObject);
procedure ButtonAddClick(Sender: TObject);
procedure ButtonDivClick(Sender: TObject);
procedure ButtonIgualClick(Sender: TObject);
procedure ButtonLimparClick(Sender: TObject);
procedure ButtonMultClick(Sender: TObject);
procedure ButtonSalvarClick(Sender: TObject);
procedure ButtonSubClick(Sender: TObject);
procedure ButtonVirgClick(Sender: TObject);
procedure FormCloseQuery(Sender: TObject; var CanClose: boolean);
procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
procedure MenuItemHistClick(Sender: TObject);
procedure TimerHoraTimer(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
end;
var
CalculadoraLe: TCalculadoraLe;
add:real;
subt:real;
mult:real;
divis:real;
igual:real;
igual2:real;
add1:boolean;
subt1:boolean;
mult1:boolean;
divis1:boolean;
hist:Integer;
implementation
{$R *.lfm}
{ TCalculadoraLe }
procedure TCalculadoraLe.Button1Click(Sender: TObject);
begin
Visor.Caption:=Visor.Caption+'1';
end;
procedure TCalculadoraLe.Button0Click(Sender: TObject);
begin
Visor.Caption:=Visor.Caption+'0';
end;
procedure TCalculadoraLe.BotaoSairClick(Sender: TObject);
begin
Close;
end;
procedure TCalculadoraLe.BotaoAjudaAutorClick(Sender: TObject);
begin
ShowMessage('Criado por: Alessandro Roberto , Data: 10/01/2013');
end;
procedure TCalculadoraLe.Button2Click(Sender: TObject);
begin
Visor.Caption:=Visor.Caption+'2';
end;
procedure TCalculadoraLe.Button3Click(Sender: TObject);
begin
Visor.Caption:=Visor.Caption+'3';
end;
procedure TCalculadoraLe.Button4Click(Sender: TObject);
begin
Visor.Caption:=Visor.Caption+'4';
end;
procedure TCalculadoraLe.Button5Click(Sender: TObject);
begin
Visor.Caption:=Visor.Caption+'5';
end;
procedure TCalculadoraLe.Button6Click(Sender: TObject);
begin
Visor.Caption:=Visor.Caption+'6';
end;
procedure TCalculadoraLe.Button7Click(Sender: TObject);
begin
Visor.Caption:=Visor.Caption+'7';
end;
procedure TCalculadoraLe.Button8Click(Sender: TObject);
begin
Visor.Caption:=Visor.Caption+'8';
end;
procedure TCalculadoraLe.Button9Click(Sender: TObject);
begin
Visor.Caption:=Visor.Caption+'9';
end;
procedure TCalculadoraLe.ButtonAddClick(Sender: TObject);
begin
add:=StrToFloat(Visor.Caption);
add1:=true;
visor.Caption:='';
hist:=1;
end;
procedure TCalculadoraLe.ButtonDivClick(Sender: TObject);
begin
divis:=StrToFloat(Visor.Caption);
divis1:=true;
Visor.Caption:='';
hist:=4;
end;
procedure TCalculadoraLe.ButtonIgualClick(Sender: TObject);
begin
igual:=StrToFloat(Visor.Caption);
if add1=true then
igual2:=add+igual
;
Visor.Caption:=FloatToStr(igual2);
add1:=false;
if subt1=true then
igual2:=subt-igual
;
Visor.Caption:=FloatToStr(igual2);
subt1:=false;
if mult1=true then
igual2:=mult*igual
;
Visor.Caption:=FloatToStr(igual2);
mult1:=false;
if divis1=true then
igual2:=divis/igual
;
Visor.Caption:=FloatToStr(igual2);
divis1:=false;
end;
procedure TCalculadoraLe.ButtonLimparClick(Sender: TObject);
begin
Visor.Caption:='';
add:=0;
subt:=0;
mult:=0;
divis:=0;
igual2:=0;
igual:=0;
add1:=false;
subt1:=false;
mult1:=false;
divis1:=false;
end;
procedure TCalculadoraLe.ButtonMultClick(Sender: TObject);
begin
mult:=StrToFloat(Visor.Caption);
mult1:=true;
Visor.Caption:='';
hist:=3;
end;
procedure TCalculadoraLe.ButtonSalvarClick(Sender: TObject);
begin
if ((add1=false) and (hist=1)) then
Form1.Historico.Lines.Append(DateToStr(date) + ' - ' + TimeToStr(Time) + ' >> ' +
FloatToStr(add) + ' + ' + FloatToStr(igual) + ' = ' + FloatToStr(igual2));
if ((subt1=false) and (hist=2)) then
Form1.Historico.Lines.Append(DateToStr(date) + ' - ' + TimeToStr(Time) + ' >> ' +
FloatToStr(subt) + ' - ' + FloatToStr(igual) + ' = ' + FloatToStr(igual2));
if ((divis1=false)and (hist=4)) then
Form1.Historico.Lines.Append(DateToStr(date) + ' - ' + TimeToStr(Time) + ' >> ' +
FloatToStr(divis) + ' / ' + FloatToStr(igual) + ' = ' + FloatToStr(igual2));
if ((mult1=false) and (hist=3)) then
Form1.Historico.Lines.Append(DateToStr(date) + ' - ' + TimeToStr(Time) + ' >> ' +
FloatToStr(mult) + ' x ' + FloatToStr(igual) + ' = ' + FloatToStr(igual2));
end;
procedure TCalculadoraLe.ButtonSubClick(Sender: TObject);
begin
subt:=StrToFloat(Visor.Caption);
subt1:=true;
Visor.Caption:='';
hist:=2;
end;
procedure TCalculadoraLe.ButtonVirgClick(Sender: TObject);
begin
Visor.Caption:=Visor.Caption+',';
end;
procedure TCalculadoraLe.FormCloseQuery(Sender: TObject; var CanClose: boolean);
begin
if MessageDlg('Deseja Realmente SAIR ?', mtConfirmation,
mbOKCancel,0)= mrCancel then CanClose:=False;
end;
procedure TCalculadoraLe.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
case Key of
13 :ButtonIgual.Click; // Tecla Enter
27 :BotaoSair.Click; // Tecla Esc
46 :ButtonLimpar.Click; // Tecla Delete
96 :Button0.Click ; // Tecla 0
97 :Button1.Click ; // Tecla 1
98 :Button2.Click ; // Tecla 2
99 :Button3.Click ; // Tecla 3
100 :Button4.Click ; // Tecla 4
101 :Button5.Click ; // Tecla 5
102 :Button6.Click ; // Tecla 6
103 :Button7.Click ; // Tecla 7
104 :Button8.Click ; // Tecla 8
105 :Button9.Click ; // Tecla 9
106 :ButtonMult.Click ; // Tecla "*"
107 :ButtonAdd.Click ; // Tecla "+"
109 :ButtonSub.Click ; // Tecla "-"
111 :ButtonDiv.Click ; // Tecla "/"
110 :ButtonVirg.Click; // Tecla Virgula
else
ShowMessage('Tecla Não Válida')
end;
end;
procedure TCalculadoraLe.MenuItemHistClick(Sender: TObject);
begin
form1.Show;
end;
procedure TCalculadoraLe.TimerHoraTimer(Sender: TObject);
begin
StatusBar1.Panels[0].Text:=TimeToStr(Time);
end;
end.
Código fonte Histórico da Calculadora
unit unitHistorico;{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls;
type
{ TForm1 }
TForm1 = class(TForm)
Button1: TButton;
Historico: TMemo;
procedure Button1Click(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.Button1Click(Sender: TObject);
begin
form1.close;
end;
end.
Link para download do código fonte mais executável : http://www.4shared.com/folder/8yX8qmk2/Projetos_Lazarus.html
Até a próxima.....
Nenhum comentário:
Postar um comentário