Board index » delphi » DELPHI 3 SENDER : <object> Question.

DELPHI 3 SENDER : <object> Question.

I want to be able to identify which object I am passing over with the mouse
with 1 simple
function, that reports the name back to the form in an edit box. (Not real
purpose, but simplied)
I realize that I can take all the items that I want the function to work on
by tagging them all with the
same function in the events part of the object inspector.  But how do I get
information about the SENDER, or at
least enough so that I can change the properties of the specific sender.
Hrmmm, does this make sense.

Heres the idea.

Have several small rectangles painted in a row, all white.   When mouse
passes over with the button pressed, I want them to turn green

The event handler for mousedown for all rectangles is pointed to a common
function.

e.g.
procedure TForm1.Shape1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);

begin

{ the following is what I want down}

if <sender>.color := alwhite then
    <sender>.color := algreen
else
    <sender>.color := alwhite;

end;

Of course the code doesn't work because I haven't figured out how to
determine the SENDERS real name to sub for <sender>

Any of you people out there know how to do what it is I am asking???

boro...@telusplanet.net
Sven Hansen

 

Re:DELPHI 3 SENDER : <object> Question.


Sven Hansen - Owner/Operator - Pincher Creek Garden Market IGA wrote in
message <71525o$...@priv-sys04-le0.telusplanet.net>...

Quote
>I want to be able to identify which object I am passing over with the mouse
>with 1 simple function, that reports the name back to the form in an edit
>box. (Not real purpose, but simplied)
>I realize that I can take all the items that I want the function to work on
>by tagging them all with the >same function in the events part of the
>object inspector.  But how do I get information about the SENDER, or
>at least enough so that I can change the properties of the specific
>sender. Hrmmm, does this make sense.

>Heres the idea.

>Have several small rectangles painted in a row, all white.   When mouse
>passes over with the button pressed, I want them to turn green

>The event handler for mousedown for all rectangles is pointed to a common
>function.

>e.g.
>procedure TForm1.Shape1MouseDown(Sender: TObject; Button: TMouseButton;
>Shift: TShiftState; X, Y: Integer);

>begin

>{ the following is what I want down}

>if <sender>.color := alwhite then
>    <sender>.color := algreen
>else
>    <sender>.color := alwhite;

>end;

>Of course the code doesn't work because I haven't figured out how to
>determine the SENDERS real name to sub for <sender>

>Any of you people out there know how to do what it is I am asking???

It sounds like you want to do something like
    if Sender is TShape then
      with Sender as TShape do
        if color = alwhite then
            ....
A couple of other things you should note:
1) In your example you said "if <sender>.color := alwhite then". This isn't
going to work if you use ":=" - you need to use "=".
2) From the description you gave before the example, I would think you'd be
better off putting the common code in the OnMouseMove event rather than the
OnMouseDown event, unless you specifically want the user to click.
--
Garry Knight
Computer programmer, psychotherapist, writer
ga...@garryknight.freeserve.co.uk

Re:DELPHI 3 SENDER : <object> Question.


You don't care what the senders real name is.  Sender already points to
the object you want to deal with.  You just need to make sure that you
use it as the object you know it is.

Since you have this common routine pointed to from TShapes, you can just
say:

if (Sender as TShape).color := alwhite then
    (Sender as TShape).color := algreen
else
    (Sender as TShape).color := alwhite;

Although it is common practice to say:

with Sender as TShape do
begin
  if Color = alWhite then
    Color := alGreen
  else
    Color := alWhite;
end;

[the Begin and End are not required since it's one statment, but I put them in
 to help me figure out my code.]

Sven Hansen - Owner/Operator - Pincher Creek Garden Market IGA wrote:

Quote
> I want to be able to identify which object I am passing over with the mouse
> with 1 simple
> function, that reports the name back to the form in an edit box. (Not real
> purpose, but simplied)
> I realize that I can take all the items that I want the function to work on
> by tagging them all with the
> same function in the events part of the object inspector.  But how do I get
> information about the SENDER, or at
> least enough so that I can change the properties of the specific sender.
> Hrmmm, does this make sense.

> Heres the idea.

> Have several small rectangles painted in a row, all white.   When mouse
> passes over with the button pressed, I want them to turn green

> The event handler for mousedown for all rectangles is pointed to a common
> function.

> e.g.
> procedure TForm1.Shape1MouseDown(Sender: TObject; Button: TMouseButton;
> Shift: TShiftState; X, Y: Integer);

> begin

> { the following is what I want down}

> if <sender>.color := alwhite then
>     <sender>.color := algreen
> else
>     <sender>.color := alwhite;

> end;

> Of course the code doesn't work because I haven't figured out how to
> determine the SENDERS real name to sub for <sender>

> Any of you people out there know how to do what it is I am asking???

> boro...@telusplanet.net
> Sven Hansen

Other Threads