酒杯上的碟
= TLabel.Create(Self);
with FStatus do
begin
Parent := Self;
SetBounds(10, 38, 25, 25);
BorderStyle := bsRaisedPanel;
end;
FResultEdit := TEdit.Create(Self);
FResultEdit.Parent := Self;
FResultEdit.SetBounds(5, 5, 240, 25);
FResultEdit.Alignment := taRightJustify;
FResultEdit.Font.Height := -13;
FResultEdit.Font.Name := 'Arial';
FResultEdit.Text := '0';
end;
procedure TCalculator.Calc(Sender: TObject);
const
MemoryStoreMap: array [Boolean] of string = (' M','');
var
ButtonType: TButtonType;
Temp: string;
TempValue: Single;
begin
ButtonType := TButtonType(TButton(Sender).Tag);
try
case ButtonType of
bt0..bt9:
begin
FBackSpaceValid := True;
if (FResultEdit.Text = '0') or (FCurrentValue = 0) then FResultEdit.Text := '';
FResultEdit.Text :=
FResultEdit.Text + Btns[ButtonType].Caption;
FCurrentValue := StrToFloat(FResultEdit.Text);
FRepeatValue := 0;
end;
btDecimal:
if Pos('.', FResultEdit.Text) < 1 then
begin
FCurrentValue := StrToFloat(FResultEdit.Text);
FLastValue := 0;
FResultEdit.Text :=
FResultEdit.Text + Btns[ButtonType].Caption;
end;
btPlusMinus:
begin
FCurrentValue := StrToFloat(FResultEdit.Text);
FCurrentValue := FCurrentValue * -1;
FResultEdit.Text := FloatToStr(FCurrentValue);
end;
btClearAll:
begin
FCurrentValue := 0;
FLastValue := 0;
FResultEdit.Text := '0';
FState := csNone;
end;
btClear:
begin
FCurrentValue := 0;
FResultEdit.Text := '0';
end;
btAdd:
begin
FCurrentValue := StrToFloat(FResultEdit.Text);
FState := csAdd;
FLastValue := FCurrentValue;
FCurrentValue := 0;
end;
btSubtract:
begin
FCurrentValue := StrToFloat(FResultEdit.Text);
FState := csSubtract;
FLastValue := FCurrentValue;
FCurrentValue := 0;
end;
btDivide:
begin
FCurrentValue := StrToFloat(FResultEdit.Text);
FState := csDivide;
FLastValue := FCurrentValue;
FCurrentValue := 0;
end;
btMultiply:
begin
FCurrentValue := StrToFloat(FResultEdit.Text);
FState := csMultiply;
FLastValue := FCurrentValue;
FCurrentValue := 0;
end;
btBackSpace:
if FBackSpaceValid then
begin
Temp := FResultEdit.Text;
Delete(Temp, Length(Temp),1);
if Temp = '' then Temp := '0';
FCurrentValue := StrToFloat(Temp);
FR 《酒杯上的碟(第6页)》
本文链接地址:http://www.oyaya.net/fanwen/view/173009.html
with FStatus do
begin
Parent := Self;
SetBounds(10, 38, 25, 25);
BorderStyle := bsRaisedPanel;
end;
FResultEdit := TEdit.Create(Self);
FResultEdit.Parent := Self;
FResultEdit.SetBounds(5, 5, 240, 25);
FResultEdit.Alignment := taRightJustify;
FResultEdit.Font.Height := -13;
FResultEdit.Font.Name := 'Arial';
FResultEdit.Text := '0';
end;
procedure TCalculator.Calc(Sender: TObject);
const
MemoryStoreMap: array [Boolean] of string = (' M','');
var
ButtonType: TButtonType;
Temp: string;
TempValue: Single;
begin
ButtonType := TButtonType(TButton(Sender).Tag);
try
case ButtonType of
bt0..bt9:
begin
FBackSpaceValid := True;
if (FResultEdit.Text = '0') or (FCurrentValue = 0) then FResultEdit.Text := '';
FResultEdit.Text :=
FResultEdit.Text + Btns[ButtonType].Caption;
FCurrentValue := StrToFloat(FResultEdit.Text);
FRepeatValue := 0;
end;
btDecimal:
if Pos('.', FResultEdit.Text) < 1 then
begin
FCurrentValue := StrToFloat(FResultEdit.Text);
FLastValue := 0;
FResultEdit.Text :=
FResultEdit.Text + Btns[ButtonType].Caption;
end;
btPlusMinus:
begin
FCurrentValue := StrToFloat(FResultEdit.Text);
FCurrentValue := FCurrentValue * -1;
FResultEdit.Text := FloatToStr(FCurrentValue);
end;
btClearAll:
begin
FCurrentValue := 0;
FLastValue := 0;
FResultEdit.Text := '0';
FState := csNone;
end;
btClear:
begin
FCurrentValue := 0;
FResultEdit.Text := '0';
end;
btAdd:
begin
FCurrentValue := StrToFloat(FResultEdit.Text);
FState := csAdd;
FLastValue := FCurrentValue;
FCurrentValue := 0;
end;
btSubtract:
begin
FCurrentValue := StrToFloat(FResultEdit.Text);
FState := csSubtract;
FLastValue := FCurrentValue;
FCurrentValue := 0;
end;
btDivide:
begin
FCurrentValue := StrToFloat(FResultEdit.Text);
FState := csDivide;
FLastValue := FCurrentValue;
FCurrentValue := 0;
end;
btMultiply:
begin
FCurrentValue := StrToFloat(FResultEdit.Text);
FState := csMultiply;
FLastValue := FCurrentValue;
FCurrentValue := 0;
end;
btBackSpace:
if FBackSpaceValid then
begin
Temp := FResultEdit.Text;
Delete(Temp, Length(Temp),1);
if Temp = '' then Temp := '0';
FCurrentValue := StrToFloat(Temp);
FR 《酒杯上的碟(第6页)》