Delphi   发布时间:2022-04-11  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了Delphi:不兼容的类型:’整数’和’扩展’大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我需要制定一个计划,计算出你工作时间会得到的金额.
这是代码:
unit HoursWorked_u;

interface

uses
  Windows,messages,SysUtils,Variants,Classes,Graphics,Controls,Forms,Dialogs,ExtCtrls,StdCtrls,Spin;

type
  TForm1 = class(TForm)
    lblName: TLabel;
    edtName: TEdit;
    Label1: TLabel;
    sedHours: TSpinEdit;
    btncalc: TButton;
    Panel1: TPanel;
    lblOutput: TLabel;
    Label2: TLabel;
    Panel2: TPanel;
    lblOutPutMonth: TLabel;
    labelrandom: TLabel;
    Label3: TLabel;
    seddays: TSpinEdit;
    procedure btncalcClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}
// sedHours and sedDays are SpinEdits
// Rand (R) is South African currency eg: One months work,I will recieve-
// -R10 000.00
// Where R12,50 is paid an hour.
// Need to work out how much I will get paid for how  many hours are worked.
procedure TForm1.btncalcClick(Sender: TObject);
var
    sName                       :string;
    iHours,iDays               :Integer;
    rPay                        :real;

begin
  rPay := 12.5;
  sName := edtName.Text;
  iHours := sedHours.value * rPay;
  iDays := sedDays.value * iHours;
    lblOutput.caption := sName + ' you will recieve R' + IntToStr (iHours);
    lblOutputMonth.Caption := 'you will recive R' + intToStr (iDays);
end;

end.

错误消息是:

[Error] HoursWorked_u.pas(51): Incompatible types: 'Integer' and 'Extended'

请注意:我是新手用户,所有这些都是IT功课.
任何帮助将非常感激!
提前致谢!

解决方法

错误在这里:
iHours := sedHours.value * rPay;

右侧是浮点表达式,因为rPay是浮点变量.您不能将浮点值分配给整数.您需要转换为整数.

例如,您可以舍入到最近的:

iHours := round(sedHours.value * rPay);

或者您可以使用Floor来获取小于或等于浮点值的最大整数:

iHours := Floor(sedHours.value * rPay);

或者Ceil,大于或等于浮点值的最小整数:

iHours := Ceil(sedHours.value * rPay);

对于一些更一般的建议,我建议您在遇到您不理解的错误时尝试查看文档.记录每个编译器错误.以下是E2010不兼容类型的文档:http://docwiki.embarcadero.com/RADStudio/en/E2010_Incompatible_types_-_%27%25s%27_and_%27%25s%27_%28Delphi%29

好好读一读.然给出的示例与您的案例不完全匹配,但它非常接近.编译器错误不是害怕的事情.它们带有描述性文本,您可以通过阅读它们并尝试弄清楚代码如何导致特定错误来解决您的问题.

大佬总结

以上是大佬教程为你收集整理的Delphi:不兼容的类型:’整数’和’扩展’全部内容,希望文章能够帮你解决Delphi:不兼容的类型:’整数’和’扩展’所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。