本人写了一个过程,把该过程赋给一对象事件。参数怎么设置。(50分)

  • 主题发起人 主题发起人 only_delphi
  • 开始时间 开始时间
O

only_delphi

Unregistered / Unconfirmed
GUEST, unregistred user!
本人写了一个过程,把该过程赋给一对象事件。
参数怎么设置,


unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls;

type
TForm1 = class(TForm)
Button1: TButton;
Shape1: TShape;
Edit1: TEdit;
Shape2: TShape;
Button2: TButton;
procedure set_around(Sender: Tcontrol);
procedure set_MouseDown(Sender: Tcontrol
Shift: TShiftState
X, Y: Integer);
procedure Shape1MouseUp(Sender: TObject
Button: TMouseButton;
Shift: TShiftState
X, Y: Integer);
procedure FormMouseMove(Sender: TObject
Shift: TShiftState
X,
Y: Integer);
procedure Button1MouseMove(Sender: TObject
Shift: TShiftState
X,
Y: Integer);
procedure Button1MouseDown(Sender: TObject
Button: TMouseButton;
Shift: TShiftState
X, Y: Integer);
procedure Button1MouseUp(Sender: TObject
Button: TMouseButton;
Shift: TShiftState
X, Y: Integer);
procedure Shape1MouseMove(Sender: TObject
Shift: TShiftState
X,
Y: Integer);
procedure Shape1MouseDown(Sender: TObject
Button: TMouseButton;
Shift: TShiftState
X, Y: Integer);
procedure Shape2MouseUp(Sender: TObject
Button: TMouseButton;
Shift: TShiftState
X, Y: Integer);
procedure Shape2MouseMove(Sender: TObject
Shift: TShiftState
X,
Y: Integer);
procedure Shape2MouseDown(Sender: TObject
Button: TMouseButton;
Shift: TShiftState
X, Y: Integer);
procedure FormCreate(Sender: TObject);
private
procedure set_left_top(Sender: Tcontrol);
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
flag:boolean;
old_x,old_y:integer;
implementation

{$R *.dfm}
procedure TForm1.set_around(Sender: Tcontrol);
begin
shape1.Left:=sender.Left-3;
shape1.top:=sender.top-3;
shape2.Left:=sender.Left +sender.Width div 2;
shape2.Top :=shape1.Top-2;

//shape1.Left:=sender.Left;
//shape1.Left:=sender.Left;
end;
procedure TForm1.Shape1MouseUp(Sender: TObject
Button: TMouseButton;
Shift: TShiftState
X, Y: Integer);
begin

flag:=false;

end;

procedure TForm1.FormMouseMove(Sender: TObject
Shift: TShiftState
X,
Y: Integer);
begin
edit1.Text:=inttostr(shape2.top);
end;

procedure TForm1.Button1MouseMove(Sender: TObject
Shift: TShiftState
X,
Y: Integer);
begin
if flag then
begin
//shape1.Left:=button1.Left+button1.Width div 2;
//shape1.Top:=button1.Top-4;
button1.Left:=button1.Left + (x-old_x);
button1.Top:=button1.Top +(y-old_y);
set_around(button1);
end;
end;

procedure TForm1.Button1MouseDown(Sender: TObject
Button: TMouseButton;
Shift: TShiftState
X, Y: Integer);
begin
flag:=true;
old_x:=x;
old_y:=y;
end;

procedure TForm1.Button1MouseUp(Sender: TObject
Button: TMouseButton;
Shift: TShiftState
X, Y: Integer);
begin
flag:=false;
end;

procedure TForm1.Shape1MouseMove(Sender: TObject
Shift: TShiftState
X,
Y: Integer);
begin
if flag then
begin
shape1.Top:=shape1.Top+y;
shape1.Left:=shape1.Left+x;
button1.Height:=button1.Height - y;
button1.Top:=button1.Top+y;
button1.Left:=shape1.Left;
button1.Width:=button1.Width-x;
// set_around(button1);

end;
end;

procedure TForm1.Shape1MouseDown(Sender: TObject
Button: TMouseButton;
Shift: TShiftState
X, Y: Integer);
begin
flag:=true;
end;

procedure TForm1.set_left_top(Sender: Tcontrol);
begin
//sender.Left:=sender.Left+old_x+x;

end;

procedure TForm1.Shape2MouseUp(Sender: TObject
Button: TMouseButton;
Shift: TShiftState
X, Y: Integer);
begin

flag:=false;
end;

procedure TForm1.Shape2MouseMove(Sender: TObject
Shift: TShiftState
X,
Y: Integer);
begin
if flag then
begin
shape2.Top:=shape2.Top+y;
button1.Height:=button1.Height - y;
button1.Top:=button1.Top+y;
// set_around(button1);
end;
end;

procedure TForm1.Shape2MouseDown(Sender: TObject
Button: TMouseButton;
Shift: TShiftState
X, Y: Integer);
begin
flag:=true;
end;



procedure TForm1.set_MouseDown(Sender: Tcontrol
Shift: TShiftState
X, Y: Integer);
begin
flag:=true;
old_x:=x;
old_y:=y;

end;

procedure TForm1.FormCreate(Sender: TObject);
begin
shape1.OnMouseDown:=set_mousedown(此处的参数怎样写);
// set_MouseDown();
end;

end.
 
也许上面的内容太多了,不容易看明白,其实简单写就是
过程,当然需要声明。
procedure TForm1.set_MouseDown(Sender: Tcontrol
Shift: TShiftState
X, Y: Integer);
begin
flag:=true;
old_x:=x;
old_y:=y;

end;

procedure TForm1.FormCreate(Sender: TObject);
begin
shape1.OnMouseDown:=set_mousedown(此处的参数怎样写);
// set_MouseDown();
end;

 
我用过OnKeyDown事件,不用写参数。
 
我这里要用参数的目的就是,要取该事件发生时 s鼠标的x,y值,且该过程要使用n次,也就是是可视化的组件都有该事件。
 
自定义事件要与shape的mousedown参数一致

procedure tform1.set_MouseDown(Sender: TObject
Shift: TShiftState
X, Y: Integer);

然后直接
shape1.OnMouseDown:=set_mousedown
//不用写参数;

 
上面的过程写错了 少了个Button 应该是

procedure set_MouseDown(Sender: TObject
Button: TMouseButton
Shift: TShiftState
X, Y: Integer);
 
我说的就是这个意思,自定义的函数声明以及实现时都要有相应的参数,但是赋给具体过程
时不用加参数。
 
几天了问题还是没解决
关键问题是过程中的参数用在了实际的过程中,
procedure TForm1.set_shape1_around(Sender: Twincontrol
Shift: TShiftState
X, Y: Integer);
begin
shape1.Top:=shape1.Top+y-old_y1;
shape1.Left:=shape1.Left+x-old_x1;
sender.Height:=sender.Height - y;
sender.Top:=shape1.top+3;
sender.Left:=shape1.Left+3;
sender.Width:=sender.Width-x+old_x1;
shape2.Top:=sender.Top -3;
shape2.Left:=sender.Left +sender.Width div 2;
shape3.Top:=shape3.Top+y-old_y1;
shape4.Top:=sender.top+sender.Height div 2;
shape6.Left:=sender.Left +sender.Width div 2;
shape7.left:=sender.Left-3;
shape8.Top:=sender.Top +sender.Height div 2;
shape8.Left:=sender.Left-3;
end;


如果过程中的sender换成button1那么,具体的赋给过程时是不用参数,
可是我这里的不是这样啊!
 
终于自己解决了
set_shape1_move(button1,Shift,x,y);

procedure TForm1.Shape1MouseMove(Sender: TObject
Shift: TShiftState
X,
Y: Integer);
begin
set_shape1_move(button1,Shift,x,y);//调用该过程
end;
 
后退
顶部