Ver Mensaje Individual
  #10  
Antiguo 15-05-2006
Avatar de Héctor Randolph
[Héctor Randolph] Héctor Randolph is offline
Miembro Premium
 
Registrado: dic 2004
Posts: 882
Reputación: 20
Héctor Randolph Va por buen camino
Solamente falta ajustar unos pequeños detalles para que trabaje correctamente

Prueba de esta forma:

Código Delphi [-]
unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Button1: TButton;
    Edit3: TEdit;
    Edit1: TEdit;
    Edit2: TEdit;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
  numeros: TNumeros;
begin
  {Corrige esta línea}
  numeros:=TNumeros.Create(StrToInt(Edit1.Text), StrToInt(Edit2.Text));
  Edit3.Text:=IntToStr(numeros.Suma);
  numeros.Free; {Agrega esta línea}
end;

end.

Código Delphi [-]
unit Unit2;

interface

Type
  TNumeros = class
    private
    protected
      Fa: integer;
      Fb: integer;
    public
      constructor Create(_Fa, _Fb: integer);
      function Suma: integer;
      property A:integer read Fa write Fa;
      property B:integer read Fb write Fb;
    published
end;

implementation

{TNumeros }
constructor TNumeros.Create(_Fa, _Fb: integer);
begin
    Self.Fa:=_Fa;
    Self.Fb:=_Fb; {Corrige esta línea}
end;

function TNumeros.Suma: integer;
begin
  Result:=Fa + Fb;
end;

end.

Saludos
Responder Con Cita