What's the use of a Tag property when I can't use it properly? I've had a
similar problem like this many times earlier, and I have always bypassed it
somehow, but this time I just don't want to! Here's my problem:
I've created an array of TImages called grp[i] (i=1..max). During
Initialization each object is given certain properties, and the Tag is set
to the index, that is
grp[i].Tag := i;
Also,
grp[i].OnMouseMove := Image1MouseMove;
grp[i].OnClick := Image1Click;
I need this because I want to access the object from another form and stuff
like that, and that works all right. But then I have another problem.
Image1 covers the entire form. On it, the created TImages (I'll call them
CIs) are moving around in random directions, and the user tries to click on
them. When he misses (the Image1 is clicked), I get the X and Y position of
the mouse pointer and do some stuff. When he doesn't miss, then one of the
CIs need to do the same.
Now, since clicking on a CI will not give back the same coordinates as when
clicking on the Image1 in the same spot, I need to calculate the coordinates
so that
newX := CI.Left + X;
newY := CI.Top + Y;
newX and newY are global variables.
You get the idea. And here comes the problem: I cannot get the CI's Left or
any other property, because I cannot access it. Like this:
procedure TForm1.Image1MouseMove(Sender: TObject; Shift: TShiftState;
X, Y: Integer);
begin
with Sender do begin
if (ClassType = TImage) then begin
newX := X;
newY := Y
end else if (ClassType = TPeasants) then begin
newX := X + Sender.Left; // ERROR
newY := Y + Sender.Top; // ERROR
end
end
end;
I've also tried:
newX := X + grp[Sender.Tag].Left; // ERROR
newY := Y + grp[Sender.Tag].Top; // ERROR
There is just no way I can put a correct index instead of Sender.Tag. One
solution would be to make a global variable, for example index: integer; and
then when OnClick the index gets the Tag number. However, since every CI is
tied to the Image1's OnClick property, once more I cannot get the index
number, because
if (Sender.ClassType = TCI) then
index := Sender.Tag;
will give me an error message.
Any ideas how can I solve this?
Gajo
---------------------------------------------------------------------------
New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
Website: http://www.delphi.org.nz
To UnSub, send email to: [EMAIL PROTECTED]
with body of "unsubscribe delphi"
Web Archive at: http://www.mail-archive.com/delphi%40delphi.org.nz/