加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

Delphi 7:将图像附加到鼠标

发布时间:2020-12-15 04:34:41 所属栏目:大数据 来源:网络整理
导读:我希望T Image的衍生版本在单击时跟随Cursor,并在再次单击时停止跟随. 为此,我创建了一个名为’Attached’的指针,指向TImage或衍生物. var Attached: ^TImage; 我还设置了Timage的派生,在单击时调用过程ChangeAttachState. 现在,在ChangeAttachState过程中,
我希望T Image的衍生版本在单击时跟随Cursor,并在再次单击时停止跟随.
为此,我创建了一个名为’Attached’的指针,指向TImage或衍生物.
var Attached: ^TImage;

我还设置了Timage的派生,在单击时调用过程ChangeAttachState.

现在,在ChangeAttachState过程中,我想更改它指向所单击图像的指针,或者在已附加图像时指向nil.在代码中:

procedure TForm1.ChangeAttachState(Sender:TObject);
begin
  if Attached = nil then
    Attached := @Sender
  else
    Attached := nil;
end;

但是,“Attached:= @Sender”行似乎不起作用,当我想使用指针即将图像移动到右侧时,会导致访问冲突.

我认为指针指向错误的位置.如何使指针指向正确的保存地址,或者使用其他方法使点击的图像跟随鼠标?

(我希望我使用正确的技术术语,因为英语不是我的母语)

解决方法

一个对象已经是一个指针,声明你的附加了一个TImage(而不是^ TImage),你可以在“ChangeAttachedState”(而不是Attached:= @Sender)中将Attached:= Sender分配给它作为TImage.

然后,您可以在窗体上附加鼠标移动处理程序,如下所示:

procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,Y: Integer);
begin
  if Assigned(Attached) then begin
    Attached.Left := X;
    Attached.Top := Y;
  end;
end;

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读