如何得到这个值呢??

dengyueguang 2003-08-20 02:13:19
var arrimg:Array[1..5]of TImage;
i:Integer;
begin
For i:= 1 to 5 do
begin
arrimg[i]:=TImage.Create(Self);
arrimg[i].Parent:=Self;
arrimg[i].Top:=10+i*2;
arrimg[i].Left:=10+i*2;
arrimg[i].Picture.LoadFromFile('D:\Image Source\1122.bmp');
end;
end;
我用上面程序在窗体上创建了5个image控件,请教:
当我要移动第2个或者第3个image控件,如何得到这个i值呢?
...全文
62 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
dengyueguang 2003-08-20
  • 打赏
  • 举报
回复
如果加上
if sender is Timage then
不执行下面的程序
begin
arrimg[i].Tag:=i;
arrimg[i].Top:=p.Y-toolbar1.Height*2;
arrimg[i].Left:=p.x;
arrimg[i].Cursor:=crHandPoint;
end;
dengyueguang 2003-08-20
  • 打赏
  • 举报
回复
还是不行,出错"invalid class typecast "
swayi21 2003-08-20
  • 打赏
  • 举报
回复
arrimg[i].Tag := i;

這就是 Tag 屬性存在的一個理由。
zhuojohn 2003-08-20
  • 打赏
  • 举报
回复
procedure TForm1.Image1Click(Sender: TObject);
var
img:TImage;
i:Integer;
begin
img:=Sender as TImage;
i:=(Img.Top-10)div 2;
ShowMessage(Format('No.%d image selected',[i]));
end;

end.
windindance 2003-08-20
  • 打赏
  • 举报
回复
所有的事件中都有Sender:TObject参数
For i:= 1 to 5 do
begin
arrimg[i]:=TImage.Create(Self);
arrimg[i].Parent:=Self;
arrimg[i].Tag := i;

if Sender is TImage then
(Sender as TImage).Tag
dengyueguang 2003-08-20
  • 打赏
  • 举报
回复
我的意思是如果我将鼠标放置在任意一个image控件上,
我想拖动任意一个控件如何得到这个索引值呢?

5,388

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧