epson 发表于 2019-6-11 00:14:22

谁帮我看看到底错在那里好吗!谢谢

unit Unit1;

interface

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

type
TForm1 = class(TForm)
    Image1: TImage;
    Edit1: TEdit;
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Button4: TButton;
    Button5: TButton;
    Button6: TButton;
    Button7: TButton;
    Button8: TButton;
    Button9: TButton;
    Button10: TButton;
    Button11: TButton;
    Button12: TButton;
    Button13: TButton;
    Button14: TButton;
    Button15: TButton;
    Button16: TButton;
    Button17: TButton;
    Button18: TButton;
    Button19: TButton;
    Button20: TButton;
    Button21: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button5Click(Sender: TObject);
    procedure Button6Click(Sender: TObject);
    procedure Button7Click(Sender: TObject);
    procedure Button9Click(Sender: TObject);
    procedure Button10Click(Sender: TObject);
    procedure Button11Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure Button13Click(Sender: TObject);
    procedure Button8Click(Sender: TObject);
    procedure Button15Click(Sender: TObject);
    procedure Button12Click(Sender: TObject);
    procedure Button16Click(Sender: TObject);
    procedure Button18Click(Sender: TObject);
    procedure Button17Click(Sender: TObject);
    procedure Button21Click(Sender: TObject);
    procedure Button19Click(Sender: TObject);
    procedure Button20Click(Sender: TObject);
    procedure Button14Click(Sender: TObject);
private
    { Private declarations }
public
    { Public declarations }
end;

var
Form1: TForm1;

implementation
var
result:real;
temp:real;
oper:char;
{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
    Edit1.Text:=Edit1.Text+'7';
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
    Edit1.Text:=Edit1.Text+'8';
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
    Edit1.Text:=Edit1.Text+'9';
end;

procedure TForm1.Button5Click(Sender: TObject);
begin
   Edit1.Text:=Edit1.Text+'4';
end;

procedure TForm1.Button6Click(Sender: TObject);
begin
    Edit1.Text:=Edit1.Text+'5';
end;

procedure TForm1.Button7Click(Sender: TObject);
begin
   Edit1.Text:=Edit1.Text+'6';
end;

procedure TForm1.Button9Click(Sender: TObject);
begin
    Edit1.Text:=Edit1.Text+'1';
end;

procedure TForm1.Button10Click(Sender: TObject);
begin
    Edit1.Text:=Edit1.Text+'2';
end;

procedure TForm1.Button11Click(Sender: TObject);
begin
   Edit1.Text:=Edit1.Text+'3';
end;

procedure TForm1.Button4Click(Sender: TObject);
begin
    Edit1.Text:=Edit1.Text+'0';
end;

procedure TForm1.Button13Click(Sender: TObject);
begin
    Edit1.Text:=Edit1.Text+'00';
end;

procedure TForm1.Button20Click(Sender: TObject);
begin
Edit1.Text := Copy(Edit1.Text,0,Length(Edit1.Text)-1);
Edit1.SetFocus;
Edit1.selstart:=length(Edit1.Text);
end;

procedure TForm1.Button14Click(Sender: TObject);
begin
    close;
end;

procedure TForm1.Button8Click(Sender: TObject);
begin
    Edit1.Text:=Edit1.Text+'.';
end;

procedure TForm1.Button15Click(Sender: TObject);
begin
   Temp:=StrToFloat(edit1.Text );
   Edit1.Text:=Edit1.Text+'×';
   oper:='*';
end;

procedure TForm1.Button12Click(Sender: TObject);
begin
   temp:=strtofloat(edit1.Text );
   Edit1.Text:=Edit1.Text+'÷';
   oper:='/';
end;

procedure TForm1.Button16Click(Sender: TObject);
begin
   temp:=strtofloat(edit1.text);
   Edit1.Text:=Edit1.Text+'-';
   oper:='-';
end;

procedure TForm1.Button18Click(Sender: TObject);
begin
    temp:=strtofloat(edit1.Text );
    Edit1.Text:=Edit1.Text+'+';
    oper:='+';
end;

procedure TForm1.Button17Click(Sender: TObject);
begin
    temp:=strtofloat(edit1.Text );
    Edit1.Text:=floattostr(temp/100);
end;

procedure TForm1.Button21Click(Sender: TObject);
begin
   Edit1.Text:=' ';
end;

procedure TForm1.Button19Click(Sender: TObject);
begin

Case oper of
    '+':result:=temp+strtofloat(edit1.Text );
    '-':result:=temp-strtofloat(edit1.Text );
    '*':result:=temp*strtofloat(edit1.Text );
    '/':result:=temp/strtofloat(edit1.Text );

end;


END.
最后这里不能通过

cplus 发表于 2019-8-17 18:30:34

是什么问题,能说的具体一些吗?比如编译时,提示什么?

心驰神往 发表于 2020-12-22 13:26:47

你这是计算器吧,case后面的表达式必须是顺序类型。应该是你这个表达式类型不正确

rabbin 发表于 2023-1-14 17:51:04

procedure TForm1.Button19Click(Sender: TObject);
begin
Case oper of
    '+':result:=temp+strtofloat(edit1.Text );
    '-':result:=temp-strtofloat(edit1.Text );
    '*':result:=temp*strtofloat(edit1.Text );
    '/':result:=temp/strtofloat(edit1.Text );
end;
END.

rabbin 发表于 2023-1-14 17:51:33

少了一个 end;

rabbin 发表于 2023-1-14 17:52:28

procedure TForm1.Button19Click(Sender: TObject);
begin
    Case oper of
      '+':result:=temp+strtofloat(edit1.Text );
         '-':result:=temp-strtofloat(edit1.Text );
         '*':result:=temp*strtofloat(edit1.Text );
         '/':result:=temp/strtofloat(edit1.Text );
    End;   ///少了这个 End;
end;
END.
页: [1]
查看完整版本: 谁帮我看看到底错在那里好吗!谢谢