Ver Mensaje Individual
  #18  
Antiguo 18-05-2012
Avatar de ecfisa
ecfisa ecfisa is offline
Moderador
 
Registrado: dic 2005
Ubicación: Tres Arroyos, Argentina
Posts: 10.508
Reputación: 36
ecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to behold
Hola

Pensándolo bién... no voy a ser haragán, aquí tenés el código completo:
Código Delphi [-]
unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Edit1: TEdit;
    Edit2: TEdit;
    Edit3: TEdit;
    Edit4: TEdit;
    Edit5: TEdit;
    Edit6: TEdit;
    btnPromedio: TButton;
    procedure FormCreate(Sender: TObject);
    procedure EditExit(Sender: TObject);
    procedure btnPromedioClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation  {$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
  Edit1.OnExit:= EditExit;
  Edit2.OnExit:= EditExit;
  Edit3.OnExit:= EditExit;
  Edit4.OnExit:= EditExit;
  Edit5.OnExit:= EditExit;
  Edit6.OnExit:= EditExit;
end;

procedure TForm1.EditExit(Sender: TObject);
var
  cd: Double;
begin
  with Sender as TEdit do
  begin
    if not TryStrToFloat(Text, cd) then
    begin
      ShowMessage('Error en la nota ingresada en ' + Name);      
      SetFocus
    end
  end
end;

procedure TForm1.btnPromedioClick(Sender: TObject);
var
  Prom: Double;
begin
  Prom:= (StrToFloat(Edit1.Text)+StrToFloat(Edit2.Text)+
          StrToFloat(Edit3.Text)+StrToFloat(Edit4.Text)+
          StrToFloat(Edit5.Text)+StrToFloat(Edit6.Text)) / 6;
  ShowMessage(Format('El promedio es: %8.2f',[Prom]));
end;

end.
Lo único que tenés que hacer es asignar FormCreate al evento OnCreate de Form1.


Saludos.
__________________
Daniel Didriksen

Guía de estilo - Uso de las etiquetas - La otra guía de estilo ....
Responder Con Cita