第一次使用rect对象,delphi报错~ Statement expected, but expression of type 'Integer' found
代码如下:本来是用作多表头表格的。。。procedureTForm1.StringGrid1DrawCell(Sender:TObject;ACol,ARow:Integ...
代码如下:本来是用作多表头表格的。。。
procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
var
rect1:TRect;
rect2:TRect;
rectCombine:TRect;
begin
rect1:=StringGrid1.CellRect(1,1);
rect2:=StringGrid1.CellRect(2,1);
rectCombine:=Rect(rect1.left;rect1.top;rect2.right;rect2.bottom);
StringGrid1.Canvas.DrawFocusRect(rectCombine);
end;
end. 展开
procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
var
rect1:TRect;
rect2:TRect;
rectCombine:TRect;
begin
rect1:=StringGrid1.CellRect(1,1);
rect2:=StringGrid1.CellRect(2,1);
rectCombine:=Rect(rect1.left;rect1.top;rect2.right;rect2.bottom);
StringGrid1.Canvas.DrawFocusRect(rectCombine);
end;
end. 展开
1个回答
展开全部
你的代码没有错。
错在你的代码用错地方了。哈哈
问题的根源在于:在事件OnDrawCell中,有个参数名为rect,与函数名rect重名。这样的话,局部变量rect会覆盖函数rect。
正确的写法如下:
procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
var
rect1:TRect;
rect2:TRect;
rectCombine:TRect;
begin
rect1:=StringGrid1.CellRect(1,1);
rect2:=StringGrid1.CellRect(2,1);
rectCombine:=Classes.Rect(rect1.left;rect1.top;rect2.right;rect2.bottom);
StringGrid1.Canvas.DrawFocusRect(rectCombine);
end;
end.
错在你的代码用错地方了。哈哈
问题的根源在于:在事件OnDrawCell中,有个参数名为rect,与函数名rect重名。这样的话,局部变量rect会覆盖函数rect。
正确的写法如下:
procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
var
rect1:TRect;
rect2:TRect;
rectCombine:TRect;
begin
rect1:=StringGrid1.CellRect(1,1);
rect2:=StringGrid1.CellRect(2,1);
rectCombine:=Classes.Rect(rect1.left;rect1.top;rect2.right;rect2.bottom);
StringGrid1.Canvas.DrawFocusRect(rectCombine);
end;
end.
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询