Ahora hizo mi calculadora y quedo bueno. Abajo mis codigos: Esta es la Unit donde yo implente mis classes.
Código Delphi
[-]unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;
type
TCalculadora = class
private
FOp1, FOp2: integer;
procedure SetOp1(Value: integer);
procedure SetOp2(Value: integer);
function GetOp1: integer;
function GetOp2: integer;
public
property Op1: integer read GetOp1 write SetOp1;
property Op2: integer read GetOp2 write SetOp2;
function Soma: integer;
function Subtrai: integer;
function Multiplica: integer;
function Divide: double;
function Fatora: integer;
function Resta: integer;
end;
implementation
function TCalculadora.Divide: double;
begin
result := FOp1 / FOp2;
end;
function TCalculadora.Fatora: integer;
var
N,i:Integer;
begin
N := FOp2;
for i := 1 to N - 1 do
N := N * i;
result := N;
end;
function TCalculadora.GetOp1: integer;
begin
Result := FOp1;
end;
function TCalculadora.GetOp2: integer;
begin
Result := FOp2;
end;
function TCalculadora.Multiplica: integer;
var
i,j:Integer;
begin
i := 1;
j := FOp1;
while i < FOp2 do
begin
FOp1 := Fop1 + j;
inc(i);
end;
Result := FOp1;
end;
function TCalculadora.Resta: integer;
begin
end;
procedure TCalculadora.SetOp1(Value: integer);
begin
FOp1 := Value;
end;
procedure TCalculadora.SetOp2(Value: integer);
begin
FOp2 := Value;
end;
function TCalculadora.Soma: integer;
begin
result := FOp1 + FOp2;
end;
function TCalculadora.Subtrai: integer;
begin
result := Fop1 - Fop2;
end;
end.
Ahora otra Unit donde este mi llamada a la classe
Código Delphi
[-]unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Unit2, StdCtrls, Buttons;
type
TForm1 = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
BitBtn3: TBitBtn;
BitBtn4: TBitBtn;
BitBtn5: TBitBtn;
procedure BitBtn1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure BitBtn2Click(Sender: TObject);
procedure BitBtn3Click(Sender: TObject);
procedure BitBtn4Click(Sender: TObject);
procedure BitBtn5Click(Sender: TObject);
private
FCalc: TCalculadora;
public
property Calc: TCalculadora read FCalc write FCalc;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.BitBtn1Click(Sender: TObject);
begin
FCalc.Op1 := StrToInt(Edit1.Text);
FCalc.Op2 := StrToInt(Edit2.Text);
Edit3.Text := IntToStr(Calc.Soma);
end;
procedure TForm1.BitBtn2Click(Sender: TObject);
begin
FCalc.Op1 := StrToInt(Edit1.Text);
FCalc.Op2 := StrToInt(Edit2.Text);
Edit3.Text := IntToStr(Calc.Subtrai);
end;
procedure TForm1.BitBtn3Click(Sender: TObject);
begin
FCalc.Op1 := StrToInt(Edit1.Text);
FCalc.Op2 := StrToInt(Edit2.Text);
Edit3.Text := IntToStr(Calc.Multiplica);
end;
procedure TForm1.BitBtn4Click(Sender: TObject);
begin
FCalc.Op1 := StrToInt(Edit1.Text);
FCalc.Op2 := StrToInt(Edit2.Text);
Edit3.Text := FloatToStr(Calc.Divide);
end;
procedure TForm1.BitBtn5Click(Sender: TObject);
begin
FCalc.Op1 := StrToInt(Edit1.Text);
FCalc.Op2 := StrToInt(Edit2.Text);
Edit3.Text := IntToStr(Calc.Fatora);
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
FreeAndNil(FCalc);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
FCalc := TCalculadora.Create;
end;
end.
Esta funciono con poco codigo, que es mi abjetivo.