I want to dynamically create TImage controls and then drag and drop them. But if I want to assign the procedure used for the dragging to an event of this Image, it gives me:
Error: Wrong number of parameters specified for call to "ClickEvent"
This is my code for the dragging:
procedure ClickEvent(Sender:TObject; Button:TMouseButton; Shift:TShiftstate; X,Y:Integer);
begin
if Button = mbLeft then TControl(Sender).BeginDrag(False);
end;
And here I create the Image and add the properties:
procedure SpawnCard(Ort:TWinControl; sKarte:TKarteClass; Liste: Array of TKarte; BilderListe:Array of TCustomImage);
var
Bild:TImage;
begin
Liste[High(Liste)]:=sKarte.Create();
Bild:=TImage.Create(Combat);
with Bild do
begin
OnMouseDown:=ClickEvent;
Parent:=Ort;
Top:=1;
Left:=200*length(BilderListe);
width:=200;
height:=300;
Proportional:=True;
Stretch:=True;
Picture.LoadFromFile(Liste[High(Liste)].PicPath);
end;
BilderListe[High(BilderListe)]:=Bild;
end;
I don't want to call ClickEvent, I just want to assign it to the event.
TImage.OnMouseDown(inherited from itsTControlparent class) is aTMouseEventproperty.As you can see, it's declared as "of object", which means it expects a method pointer (See the Method Pointers section).
Example 1:
Declare the
ClickEventon the form (or any other object):Then you can assign it as follows:
Example 2:
Declare the
ClickEventas a class method:Then you can assign it as follows: