试编写代码如下:
procedure 桐数TForm1.Button1Click(Sender: TObject);
var total: Double;
begin
total := StrToFloat(edtPrice1.Text) * StrToInt(edtNum1.Text) +
StrToFloat(edtPrice2.Text) * StrToInt(edtNum2.Text) +
StrToFloat(edtPrice3.Text) * StrToInt(edtNum3.Text);
ShowMessage('共计 ' + FloatToStr(total) + ' 元。');
end;
procedure TForm1.edtPrice1KeyPress(Sender: TObject; var Key: Char);
begin
伍轮敬 if not (Key 腔慎in ['0'..'9','.']) then
Key := #0;
end;
procedure TForm1.edtNum1KeyPress(Sender: TObject; var Key: Char);
begin
if not (Key in ['0'..'9']) then
Key := #0;
end;
运行效果截图如下: