Delphi - alguna ayuda para hacer una calculadora

 
Vista:
sin imagen de perfil

alguna ayuda para hacer una calculadora

Publicado por Federico (39 intervenciones) el 07/09/2014 01:15:56
Hola gente necesito ayuda para hace una calculadora trigonométrica con reconocimiento de teclas del teclado numérico.
esta hecha la calculadora basica pero necisito ayuda con lo demas, funiciones como tangente, logaritmo, potencia, raiz, etc y reconocimiento de teclas


se agradece cualquier ayuda






unit Ucalculadora;

interface

uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, {System.Classes,} Vcl.Graphics,
{Vcl.Controls,} Vcl.Forms, Vcl.Dialogs, {Vcl.StdCtrls,} Controls, StdCtrls,
Classes, Math;

type
TForm5 = class(TForm)
Btn7: TButton;
Btn8: TButton;
Btn9: TButton;
Btn4: TButton;
visor: TLabel;
Btn5: TButton;
Btn6: TButton;
Btn1: TButton;
Btn2: TButton;
Btn3: TButton;
Btn0: TButton;
sumar: TButton;
Resta: TButton;
Division: TButton;
Producto: TButton;
BtnCE: TButton;
BtnComa: TButton;
BtnIgual: TButton;
BtnDelete: TButton;
Btn_Potencia: TButton;
procedure Btn0Click(Sender: TObject);
procedure sumarClick(Sender: TObject);
procedure BtnCEClick(Sender: TObject);
procedure BtnComaClick(Sender: TObject);
function tienecoma (s:string): boolean;
procedure BtnIgualClick(Sender: TObject);
procedure RestaClick(Sender: TObject);
procedure ProductoClick(Sender: TObject);
procedure DivisionClick(Sender: TObject);
function igual: string;
procedure BtnDeleteClick(Sender: TObject);
procedure Btn_PotenciaClick(Sender: TObject);
private
{ Private declarations }
resultado:boolean;
op2 : Extended; //real extendido 2
op1 : Extended; //real extendido
op : Integer; //almacenar el tipo de operacion
public
{ Public declarations }
procedure onKeypress(Sender: TObject; var Key: Word; Shift: TShiftState);

end;

var
Form5: TForm5;

implementation
{$R *.dfm}
function TForm5.tienecoma(s: string):boolean ;
var
i :integer;
begin
i:= 1;
while (i<= length (s) ) and (s [i] <> ',') do
if s[i] <> ',' then
inc(i);
if s[i] = ',' then
Result:= True
else
Result := false;
end;

function TForm5.igual:string;
begin
op2:= strtofloat (visor.Caption);
case op of
1:igual:=floattostr (op1 + op2);
2:igual:=floattostr (op1 - op2);
3:igual:=floattostr (op1 * op2);
4: if op2 <> 0 then
igual:=floattostr (op1 / op2);
else
begin
application.messagebox (' No se puede dividir por cero','Calculadora',mb_ok+mb_iconerror);
abort;
end;
end;
end;

procedure TForm5.Btn0Click(Sender: TObject);
begin
if sender is TButton and (visor.Caption = '0') then
visor.Caption := (sender as TButton).caption
else
if not resultado then
visor.Caption:=visor.Caption + (sender as TButton).caption
else
visor.Caption :=(sender as TButton).Caption;
resultado:=false;
end;


procedure TForm5.BtnCEClick(Sender: TObject);
begin
visor.Caption:=floattostr(0);
op1:=0;
op:=0;
end;


procedure TForm5.BtnComaClick(Sender: TObject);
begin
if not tienecoma (visor.Caption) then
visor.Caption:= visor.Caption + ',';
end;


procedure TForm5.DivisionClick(Sender: TObject);
begin
if op=0 then
begin
op1:= strtofloat(visor.Caption);
op:=4;
resultado:=true
end
else
begin
visor.Caption:=igual;
op1:=strtofloat (visor.Caption);
op:=4;
resultado:=true;
end;
end;


procedure TForm5.ProductoClick(Sender: TObject);
begin
if op=0 then
begin
op1:= strtofloat(visor.Caption);
op:=3;
resultado:=true
end
else
begin
visor.Caption:=igual;
op1:=strtofloat (visor.Caption);
op:=3;
resultado:=true;
end;
end;




procedure TForm5.RestaClick(Sender: TObject);
begin
if op=0 then
begin
op1:= strtofloat(visor.Caption);
op:=2;
resultado:=true
end
else
begin
visor.Caption:=igual;
op1:=strtofloat (visor.Caption);
op:=2;
resultado:=true;
end;
end;



procedure TForm5.sumarClick(Sender: TObject);
begin

if op=0 then
begin
op1:= strtofloat(visor.Caption);
op:=1;
resultado:=true
end
else
begin
visor.Caption:=igual;
op1:=strtofloat (visor.Caption);
op:=1;
resultado:=true;
end;
end;
procedure TForm5.BtnIgualClick(Sender: TObject);
begin
visor.Caption := igual;
end;


procedure TForm5.BtnDeleteClick(Sender: TObject);
var
s:string;
begin
s:=visor.Caption;
delete (s,length(s),1);
visor.Caption:=s;
if visor.Caption ='' then
visor.caption := '0';
end;


//****** procedimiento fallido para hacer que reconosca las teclas del teclado *****

procedure TForm5.onKeypress(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
case key of
vk_numpad0: visor.Caption := visor.Caption + '0';// Tecla 0 del Keypad
{ VK_NUMPAD1 : '1';
VK_NUMPAD2 :'2';
VK_NUMPAD9 :'9'; // Tecla 9 del Keypad
VK_MULTIPLY : '*'; // Tecla multiplicación (numeric keypad)
VK_ADD :'+'; // Tecla suma (numeric keypad)
VK_SEPARATOR:','; // Tecla separador (numeric keypad)
VK_SUBTRACT :'-'; // Teclma resta (numeric keypad)
VK_DECIMAL : ',';// Tecla decimal (numeric keypad)
VK_DIVIDE : ´/´;// Tecla división (numeric keypad) }
end;
end;


end.
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de viveba
Val: 16
Ha mantenido su posición en Delphi (en relación al último mes)
Gráfica de Delphi

alguna ayuda para hacer una calculadora

Publicado por viveba (16 intervenciones) el 08/09/2014 01:17:43
en principio, ten en cuenta la conversión a radianes, ya que la funciones trigonométricas de Pascal solo trabajan en radianes (sin, cos, y no recuerdo más)
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar