gpt4 book ai didi

delphi - 在鼠标上输入TShape

转载 作者:行者123 更新时间:2023-12-03 19:18:13 24 4
gpt4 key购买 nike

我有一个TMachine类,也就是TShape类

unit MachineShape;


interface

uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, extctrls,myDataModule,Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;

type

TMachine = class(TShape)
private
{ Private declarations }
public
{ Public declarations }
procedure PlaceShape(sizeW,sizeH :integer; name, order,asset : string);
end;
implementation



Procedure TMachine.PlaceShape(sizeW,sizeH :integer; name, order,asset : string);
begin
self.width := sizeW;
self.height := sizeH;
self.top := 136;
self.left := MyDataModule.fDB.LastX +2;//set left
MyDataModule.fDB.lastx := left + sizeW;
end;



end.


我将如何为此添加onmouseenter代码?因此,在运行时添加形状时,鼠标输入代码将具有自己的形状。像这样的东西,我知道这行不通..但是也许它将告诉你我想要做什么?因此,当我创建TMachine时,我会将名称和编号传递给此过程,这将使onmouseenter过程使用我发送的名称/编号进行更新。

Procedure TMachine.EditMouseEnter(name,number :string);
begin
....onmouseenter(Label2.Caption := name AND label3.caption := Number)...
end

最佳答案

添加一个OnMouseEnter事件:

type
TMachineEvent = procedure(Sender: TMachine) of object;

TMachine = class(TShape)
private
FOnMouseEnter: TMachineEvent;
...
procedure CMMouseEnter(var Message: TMessage); message CM_MOUSEENTER;
protected
procedure DoMouseEnter; virtual;
published
property OnMouseEnter: TMachineEvent read FOnMouseEnter write FOnMouseEnter;
...
end;

implementation

{ TMachine }

procedure TMachine.CMMouseenter(var Message: TMessage);
begin
DoMouseEnter;
inherited;
end;

procedure TMachine.DoMouseEnter;
begin
if Assigned(FOnMouseEnter) then
FOnMouseEnter(Self);
end;


并在运行时分配该事件:

procedure TForm1.CreateMachine;
var
Machine: TMachine;
begin
Machine := TMachine.Create(Self);
Machine.SetBounds(...);
Machine.OnMouseEnter := MachineMouseEnter;
Machine.Parent := Self;
end;

procedure TForm1.MachineMouseEnter(Sender: TMachine);
begin
Label2.Caption := Sender.Name;
Label3.Caption := Sender.Number;
end;

关于delphi - 在鼠标上输入TShape,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14560929/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com