首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

这样求form1的中心坐标为什么会报“Incompatible types”异常

2012-02-12 
这样求form1的中心坐标为什么会报“Incompatible types”错误unitUnit1interfaceusesWindows,Messages,SysU

这样求form1的中心坐标为什么会报“Incompatible types”错误
unit   Unit1;

interface

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

type
    TForm1   =   class(TForm)
        procedure   FormPaint(Sender:   TObject);
    private
        {   Private   declarations   }
    public
        {   Public   declarations   }
    end;

var
    Form1:   TForm1;
    Canvas1:     TCanvas;
      x1   :Integer;
      y1   :Integer;
      x2   :Integer;
      Y2   :Integer;

implementation

{$R   *.dfm}

procedure   TForm1.FormPaint(Sender:   TObject);
begin

      x1   :=   Form1.Left   +   (form1.Width)   /   2   ;
    {   y1   :=   Form1.Top   +   Form1.Height   /   4;
      x2   :=   Form1.Left   +   form1.Width   *   3   /   4;
      y2   :=   Form1.Top   +   Form1.Height   *   3   /4;     }

      canvas1.Ellipse(x1,y1,x2,y2);
end;

end.

  x1   :=   Form1.Left   +   (form1.Width)   /   2   ;   报错
如果改成
  x1   :=   Form1.Left   +   (form1.Width)   ;   就没有错误
为什么?


[解决办法]
x1 := Form1.Left + (form1.Width) div 2 ;
{ y1 := Form1.Top + Form1.Height div 4;
x2 := Form1.Left + form1.Width * 3 div 4;
y2 := Form1.Top + Form1.Height * 3 div 4; }

整数运算除用div

热点排行