delphi 疑问:incompatible types string and extended
新写了个delphi程序:unittest3001;interfaceusesWindows,Messages,SysUtils,Variants,Classes,Gra...
新写了个 delphi 程序 :
unit test3001;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Label1: TLabel;
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Button1: TButton;
Button2: TButton;
procedure button1click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.button1click(Sender: TObject);
var
a,b,c,s,area,real,str1:string;
begin
a:=strtofloat(Edit1.Text);
b:=strtofloat(Edit2.Text);
c:=strtofloat(Edit3.Text);
s:=(a+b+c)/2;
area:=sqrt(s*(s-a)*(s-b)*(s-c));
str(area:8:3,str1);
showmessage('面积为:'+str1);
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
edit1.Text:='';
edit2.Text:='';
edit3.Text:='';
end;
end.
run的时候报错:incompatible types string and extended
请问大家应该如何解决阿? 展开
unit test3001;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Label1: TLabel;
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Button1: TButton;
Button2: TButton;
procedure button1click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.button1click(Sender: TObject);
var
a,b,c,s,area,real,str1:string;
begin
a:=strtofloat(Edit1.Text);
b:=strtofloat(Edit2.Text);
c:=strtofloat(Edit3.Text);
s:=(a+b+c)/2;
area:=sqrt(s*(s-a)*(s-b)*(s-c));
str(area:8:3,str1);
showmessage('面积为:'+str1);
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
edit1.Text:='';
edit2.Text:='';
edit3.Text:='';
end;
end.
run的时候报错:incompatible types string and extended
请问大家应该如何解决阿? 展开
1个回答
展开全部
procedure TForm1.button1click(Sender: TObject);
var
a,b,c,s,area,real,str1:real; //这里要改
begin
a:=strtofloat(Edit1.Text);
b:=strtofloat(Edit2.Text);
c:=strtofloat(Edit3.Text);
s:=(a+b+c)/2;
area:=sqrt(s*(s-a)*(s-b)*(s-c));
str(area:8:3,str1);
showmessage('面积为:'+floattostr(str1));//这里要改
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
edit1.Text:='';
edit2.Text:='';
edit3.Text:='';
end;
end.
这样应该没问题了,写程序的时候注意变量的类型,delphi是不会自动转换类型的,你定义成了字符串型,再给他付实数值,当然报错了.
var
a,b,c,s,area,real,str1:real; //这里要改
begin
a:=strtofloat(Edit1.Text);
b:=strtofloat(Edit2.Text);
c:=strtofloat(Edit3.Text);
s:=(a+b+c)/2;
area:=sqrt(s*(s-a)*(s-b)*(s-c));
str(area:8:3,str1);
showmessage('面积为:'+floattostr(str1));//这里要改
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
edit1.Text:='';
edit2.Text:='';
edit3.Text:='';
end;
end.
这样应该没问题了,写程序的时候注意变量的类型,delphi是不会自动转换类型的,你定义成了字符串型,再给他付实数值,当然报错了.
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询