Board index » delphi » Team B: I need a clue!

Team B: I need a clue!

I've been scratching my head about this for a couple of
days now:

WHY, when you do a SetBounds(Left, Top, Width+X, Height)
on a component (in this case, a TShape -- performed in a
MouseMove event) do the LEFT and TOP values get changed
as well?? This is BIZARRE BEHAVIOR. I'm trying to resize
the component, and so far, this doesn't seem possible.
I can drag and move the object with no problems -- calling
SetBounds(Left+moved, Top+moved, Width, Height) works
like a champ. BUT -- if I change the Width or Height values,
everything goes to hell in a handbasket -- the Left and Top
values seem to change as well, even though I haven't changed
them in code!

Can someone PLEASE explain to me what's causing this??

Thanks ahead of time....
Chris

 

Re:Team B: I need a clue!


On Tue, 22 Sep 1998 15:11:57 -0600, "Chris Wallace"

Quote
<NOSPAM_gspi...@flash.net> wrote:
> WHY, when you do a SetBounds(Left, Top, Width+X, Height)
> on a component do the LEFT and TOP values get changed
> as well?

Please post simplified but compilable example code which consistently
demonstrates this problem. SetBounds doesn't change the Left and Top
when the Width and Height are changed -- I suspect you have nested
with statements, and are accidentally passing the Left and Top values
for the wrong control. If that doesn't help, there is something else
going on that you haven't mentioned yet.

--
Rick Rogers (TeamB) | Fenestra Technologies
http://www.fenestra.com/

Re:Team B: I need a clue!


Quote
Rick Rogers (TeamB) wrote in message

<360b3304.48292...@forums.borland.com>...

Quote
>On Tue, 22 Sep 1998 15:11:57 -0600, "Chris Wallace"
><NOSPAM_gspi...@flash.net> wrote:
>Please post simplified but compilable example code which consistently
>demonstrates this problem. SetBounds doesn't change the Left and Top
>when the Width and Height are changed -- I suspect you have nested
>with statements, and are accidentally passing the Left and Top values
>for the wrong control. If that doesn't help, there is something else
>going on that you haven't mentioned yet.

Apparently so! But since there's no "With" statements, and since
the control is a TShape descendant and thus lives in its own little
world, I can't for the life of me see where this can fail -- but it
does...

Let me know if you see something that needs attention....and thanks :)

Here's the control that descends from TShape:

-------------------------------------------------------------
  TDrawShape = class(TShape)
  private
    Moving      : boolean;
    MouseIsDown : boolean;
    StartX      : integer;
    StartY      : integer;
    SizeDir     : TResizeDirection;
    procedure Paint; override;
    procedure MouseUp(Button: TMouseButton; Shift: TShiftState;
      X, Y: Integer); override;
    procedure MouseDown(Button: TMouseButton; Shift: TShiftState;
      X, Y: Integer); override;
    procedure MouseMove(Shift: TShiftState; X, Y: Integer); override;
  end;

-------------------------------------------------------------

Here's the OnMouseDown handler:

procedure TDrawShape.MouseDown(Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
   if Button = mbLeft then
      begin
         BringToFront;
         Moving := true;
         MouseIsDown := true;
         StartX := X;
         StartY := Y;
      end;
   inherited MouseDown(Button, Shift, X, Y);
end;

-------------------------------------------------------------

Here's the OnMouseUp handler:

procedure TDrawShape.MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y:
Integer);
begin
   if Button = mbLeft then
      begin
         Cursor := crHandPoint;
         Moving := false;
         MouseIsDown := false;
      end;
   inherited MouseUp(Button, Shift, X, Y);
end;

-------------------------------------------------------------

Here's the OnMouseMove handler -- the one that's causing grief...

procedure TDrawShape.MouseMove(Shift: TShiftState; X, Y: Integer);
var
  ARect : TRect;
  DX,DY : integer;

begin
   if (Moving and MouseIsDown) then
      begin
         DX := X - StartX;
         DY := Y - StartY;

         Case SizeDir of
            rdNone       : SetBounds(Left+DX, Top+DY, Width, Height);
                           { this works like a champ -- only TopLeft is
changing }

            { THIS IS THE ONE THAT FAILS                          }
            { THE IDEA IS TO RESIZE THE CONTROL, SO IN THIS CASE, }
            { WE WANT TO MOVE THE LEFT EDGE AND ALSO INCREASE OR  }
            { DECREASE THE WIDTH OF THE CONTROL. SOMEHOW, TOP AND }
            { HEIGHT ALSO SEEM TO BE AFFECTED -- INEXPLICABLY!    }

            rdLeftEdge   : if DX < 0 then
                              SetBounds(Left+DX, Top, Width+Abs(DX), Height)
                           else
                              SetBounds(Left+DX, Top, Width-Abs(DX),
Height);

            { other cases removed for brevity }

         end;
      end
   else
      begin { mouse is not down }
            { check for left edge within five pixels }

         APoint := Point(X, Y);
         ARect := Rect(0, 5, 5, Height-5);
         if PtInRect(ARect, APoint) then
            begin
               Cursor  := crSizeWE;
               SizeDir := rdLeftEdge;
               Exit;
            end;

         { other conditions removed for brevity }

      end;
   inherited MouseMove(Shift, X, Y);
end;

-------------------------------------------------------------

Re:Team B: I need a clue!


Quote
In article <6u9tap$s...@forums.borland.com>, Chris Wallace wrote:
> Let me know if you see something that needs attention....and thanks :)

Just a quick thought - shouldn't your code follow the inherited method,
not precede it?

 Mike Orriss (m...@3kcc.co.uk)
 http://www.3kcc.co.uk/notetree.htm

Re:Team B: I need a clue!


Quote
Mike Orriss wrote in message ...
>In article <6u9tap$s...@forums.borland.com>, Chris Wallace wrote:
>> Let me know if you see something that needs attention....and thanks :)

>Just a quick thought - shouldn't your code follow the inherited method,
>not precede it?

Oh my God... I can't believe I did that. And you know what?
That made all the difference in the world!! THANK YOU for
pointing that out!

(This was one of those situations where you can see the
forest cuz all the damn trees are in the way...)

Re:Team B: I need a clue!


Here's another one for ya -- the shape I was playing
with wasn't a rectangle -- it was a SQUARE. Rectangles
can be sized any way you want 'em -- but a square will
ALWAYS be square even if you stretch the BoundsRect out
of "squareness" -- and when you get to a certain point,
the top/left values WILL change in order to maintain
that squareness! DUH!!! Now I'm embarassed....

Re:Team B: I need a clue!


On Wed, 23 Sep 1998 08:32:24 -0600, "Chris Wallace"

Quote
<NOSPAM_gspi...@flash.net> wrote:
> That made all the difference in the world!

I wanted to let you know I was following up on our prior thread, but
sounds like Mike has the problem sorted out.

--
Rick Rogers (TeamB) | Fenestra Technologies
http://www.fenestra.com/

Re:Team B: I need a clue!


Hi Rick,

Sorry about that -- I didn't realize you were digging
into it -- but when I saw Mike's post, curiosity got
the best of me and I tried his suggestion -- and about
hit the floor when it worked! Lessons learned...

Thanks again for all the help, it's appreciated!

Regards,
Chris

Quote
Rick Rogers (TeamB) wrote in message

<360a5663.1130...@forums.borland.com>...
Quote
>On Wed, 23 Sep 1998 08:32:24 -0600, "Chris Wallace"
><NOSPAM_gspi...@flash.net> wrote:

>I wanted to let you know I was following up on our prior thread, but
>sounds like Mike has the problem sorted out.

>--
>Rick Rogers (TeamB) | Fenestra Technologies
>http://www.fenestra.com/

Other Threads