【发布时间】:2018-10-29 22:48:37
【问题描述】:
我想将integer 与real 相乘。这是我的代码:
interface
uses
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs;
type
TForm2 = class(TForm)
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form2: TForm2;
num ,sumadh,sumadist,corectiah :integer;
cs,cf,dist,deltahprim,deltah,H:Array of integer;
corectiatest,cotareper:integer;
kh :real;
implementation
{$R *.fmx}
procedure TForm2.FormCreate(Sender: TObject);
var
i: integer;
begin
num := 3;
SetLength(cs, num);
SetLength(cf, num);
SetLength(dist, num);
SetLength(deltahprim, num);
SetLength(H, num);
sumadh := 0;
sumadist := 0;
cotareper := StrtoInt(InputBox('Cota reper nivelment',
'Valoare cota in cm', '0'));
for i := 1 to num do
begin
cs[i] := StrtoInt(InputBox('Niveleul nr' + Inttostr(i),
'Citire spate (cm)', '0'));
cf[i] := StrtoInt(InputBox('Niveleul nr' + Inttostr(i),
'Citire fata(cm)', '0'));
dist[i] := StrtoInt(InputBox('Niveleul nr' + Inttostr(i),
'Distanta intre mire(cm)', '0'));
deltahprim[i] := cs[i] - cf[i];
sumadh := sumadh + deltahprim[i];
sumadist := sumadist + dist[i];
end;
corectiah := -sumadh;
kh := corectiah / sumadist;
ShowMessage('Suma deltah = ' + Inttostr(sumadh));
ShowMessage('Suma distantelor este = ' + Inttostr(sumadist));
ShowMessage('Corectia este = ' + Inttostr(corectiah));
ShowMessage('Cota reper este = ' + Inttostr(cotareper));
for i := 1 to num do
begin
deltah[i] := deltahprim[i] + kh * dist[i];
ShowMessage('delta h compensat = ' + Inttostr(deltah[i]));
end;
end;
end.
变量kh 类似于0.0005,它需要与dist[i] 相乘。但我无法运行代码。我收到以下错误消息:
整数和双精度类型不兼容。
有没有整数到实数的函数?例如。类似InttoReal?
【问题讨论】: