Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Principal > Varios
Registrarse FAQ Miembros Calendario Guía de estilo Temas de Hoy

Grupo de Teaming del ClubDelphi

Respuesta
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 03-06-2014
cristian22 cristian22 is offline
Miembro
NULL
 
Registrado: jun 2014
Posts: 18
Poder: 0
cristian22 Va por buen camino
Carculadora ayuda

hola buenas tardes .. soy nuevo en este foro... eh estado trabajando con delphi en crear una carculadora hasta ahora voy bien, las operaciones basicas como suma, resta, division y multiplicacion me compilan bien
por ejemplo si yo hago 2+2= 4 me funciona pero quiero realizar una operacion convinada como "2+3-4*2"y cuando aprete la tecla "=" me tire el resultado de dicha operación, es decir que yo cuando realice "2+3" en el visor me muestre "5" al apretar la tecla - y al ingresar "4" y de nuevo al apretar la tecla * me muestre el resultado "1" y de nuevo ingrese "2" y al apretar esta vez la tecla "=" me salga el resultado que seria "2"
hay viene mi problema que no logro realizar esta tarea ; si alguien tiene alguna solución, o pueda guiarme para realizar este trabajo se los agradecería mucho aquí les dejo mi programa


Código Delphi [-]
type
  TForm2 = class(TForm)
    visor: TLabel;
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Button5: TButton;
    Button4: TButton;
    Button6: TButton;
    Button7: TButton;
    Button8: TButton;
    Button9: TButton;
    ButtonSuma: TButton;
    ButtonResta: TButton;
    ButtonIgual: TButton;
    ButtonProducto: TButton;
    ButtonDivision: TButton;
    button0: TButton;
    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 ButtonSumaClick(Sender: TObject);
    procedure ButtonRestaClick(Sender: TObject);
    procedure ButtonProductoClick(Sender: TObject);
    procedure ButtonDivisionClick(Sender: TObject);
    procedure ButtonIgualClick(Sender: TObject);
  private
  op: string;
  op2: real;
    op1:real;
  result:string;

    { variables}
  public
    { Public declarations }
  end;
 const
  Pi = 3.14;
var
  Form2: TForm2;


implementation

{$R *.dfm}

procedure TForm2.button0Click(Sender: TObject);
begin

   if (sender is tbutton) and (visor.Caption ='0') then
visor.Caption:= visor.Caption+(sender as tbutton).Caption

  else
visor.Caption:= visor.Caption+(sender as tbutton).Caption
end;

procedure TForm2.Button1Click(Sender: TObject);
begin

if (sender is tbutton) and (visor.Caption ='1') then
visor.Caption:= visor.Caption+(sender as tbutton).Caption

else
visor.Caption:= visor.Caption+(sender as tbutton).Caption
end;

procedure TForm2.Button2Click(Sender: TObject);
begin;
if (sender is tbutton) and (visor.Caption ='2') then
visor.Caption:= visor.Caption+(sender as tbutton).Caption

else
visor.Caption:= visor.Caption+(sender as tbutton).Caption
end;

procedure TForm2.Button3Click(Sender: TObject);
begin
   if (sender is tbutton) and (visor.Caption ='3') then
visor.Caption:= visor.Caption+(sender as tbutton).Caption

else
visor.Caption:= visor.Caption+(sender as tbutton).Caption
end;

procedure TForm2.Button4Click(Sender: TObject);
begin
if (sender is tbutton) and (visor.Caption ='4') then
visor.Caption:= visor.Caption+(sender as tbutton).Caption

else
visor.Caption:= visor.Caption+(sender as tbutton).Caption
end;

procedure TForm2.Button5Click(Sender: TObject);
begin
if (sender is tbutton) and (visor.Caption ='5') then
visor.Caption:= visor.Caption+(sender as tbutton).Caption

else
visor.Caption:= visor.Caption+(sender as tbutton).Caption
end;

procedure TForm2.Button6Click(Sender: TObject);
begin
if (sender is tbutton) and (visor.Caption ='6') then
visor.Caption:= visor.Caption+(sender as tbutton).Caption

else
visor.Caption:= visor.Caption+(sender as tbutton).Caption
end;

procedure TForm2.Button7Click(Sender: TObject);
begin
if (sender is tbutton) and (visor.Caption ='7') then
visor.Caption:= visor.Caption+(sender as tbutton).Caption

else
visor.Caption:= visor.Caption+(sender as tbutton).Caption
end;

procedure TForm2.Button8Click(Sender: TObject);
begin
if (sender is tbutton) and (visor.Caption ='8') then
visor.Caption:= visor.Caption+(sender as tbutton).Caption

else
visor.Caption:= visor.Caption+(sender as tbutton).Caption
end;

procedure TForm2.Button9Click(Sender: TObject);
begin
if (sender is tbutton) and (visor.Caption ='9') then
visor.Caption:= visor.Caption+(sender as tbutton).Caption

else
visor.Caption:= visor.Caption+(sender as tbutton).Caption
end;

procedure TForm2.ButtonDivisionClick(Sender: TObject);
begin
op2:= StrToFloat ( visor.Caption);
op:= '4';
visor.Caption:=''


end;

procedure TForm2.ButtonProductoClick(Sender: TObject);
begin

op2:= StrToFloat ( visor.Caption);
op:= '3';
visor.Caption:=''

end;

procedure TForm2.ButtonRestaClick(Sender: TObject);
begin

op2:= StrToFloat ( visor.Caption);
op:= '2';
visor.Caption:='';

end;

procedure TForm2.ButtonSumaClick(Sender: TObject);
begin

op2:= StrToFloat ( visor.Caption);
op:= '1';
visor.Caption:=''

end;

procedure TForm2.ButtonIgualClick(Sender: TObject);
 begin
 op1:= strtofloat(visor.Caption);
 if (op='1') then
 begin
 result:= floattostr(op2+op1);
  end
  else
  if (op='2') then
  begin
 result:= floattostr(op2-op1);
  end
  else
  if (op='3') then
  begin
result:= floattostr(op2*op1);
  end
    else
  if (op='4') then
  begin
    if (op1<>0) then
     begin
   result:= floattostr(op2/op1);
       end
       else
       showmessage('Divisor 0')

     end;
  visor.Caption:= result;
  end;
end.
Responder Con Cita
  #2  
Antiguo 03-06-2014
engranaje engranaje is offline
Miembro
 
Registrado: may 2011
Posts: 163
Poder: 14
engranaje Va por buen camino
Si te he entendido bien bastaria con llamar al onclick del igual justo al principio del onclick de cualquier otro boton de operación.

De todos modos a la hora de hacer una calculadora igual te valdría la pena componer una string utilizando la notación polaca inversa
http:////es.wikipedia.org/wiki/Notac...polaca_inversa
y resolverla cuando le des al igual, depende mucho de cual quieres que sea el comportamiento.
Responder Con Cita
Respuesta



Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

Temas Similares
Tema Autor Foro Respuestas Último mensaje
Ayuda BD Access? Ayuda al modificar!! DarkArias Conexión con bases de datos 4 24-08-2013 23:47:41
Instalar Ayuda (.HLP) en la Ayuda de Delphi? MasterXP Varios 6 12-04-2006 06:57:49
Ayuda para crear ayuda... Gabriel2 Varios 2 10-06-2005 00:15:18
ayuda con strtofloat, ayuda punto flotante TURING Varios 5 30-04-2004 08:03:59
Ayuda Con Instalacion De Archivos De Ayuda Legolas Varios 1 01-12-2003 14:48:03


La franja horaria es GMT +2. Ahora son las 20:15:50.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi
Copyright 1996-2007 Club Delphi