读书人

这样求form1的中心坐标为什么会报“In

发布时间: 2012-02-12 17:16:34 作者: rapoo

这样求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

读书人网 >.NET

热点推荐