#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2013
    Posts
    1
    Rep Power
    0

    Talking ReleaseCapture + OnClick Event


    Hi folks!

    I am currently facing a problem that could turn out to be simple to the likes of you experts

    I am using ReleaseCapture at the OnMouseDown Event Handler of a component (so I can drag it around using Perform(...)). However, I also need a handler for the OnClick Event. Turns out my call to ReleaseCapture cancels message handling by the component, so my OnClick handler is never called. Any ideas? Here's what my OnMouseDown handler looks like:

    procedure TDiagramObject.FrameMouseDown(Sender: TObject; Button: TMouseButton;
    Shift: TShiftState; X, Y: Integer);
    const
    SC_DRAGMOVE = $F012;
    begin
    ReleaseCapture;
    Perform(WM_SYSCOMMAND, SC_DRAGMOVE, 0);
    end;

    Thanks a lot in advance!!!
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2008
    Posts
    352
    Rep Power
    7
    I haven't tried this solution, but it may work.

    Put a timer on your frame and code your timer to do everything you had coded in the framemousedown.
    Code:
    procedure TDiagramObject.Timer1Timer(Sender: TObject);
    const
      SC_DRAGMOVE = $F012;
    begin
      ReleaseCapture;
      Perform(WM_SYSCOMMAND, SC_DRAGMOVE, 0);
    end;
    Make sure the timer is NOT enabled....

    In your framemousedown, enable the timer,
    Code:
    procedure TDiagramObject.FrameMouseDown(Sender: TObject; Button: TMouseButton;
    Shift: TShiftState; X, Y: Integer);
    begin
      Timer1.Enable;
    end;
    Now add a framemouseup, and if the time is still enabled, then interpret as a mouse click (disable the timer and execute the code you want for a mouse click)
    Code:
    procedure TDiagramObject.FrameMouseUp(Sender: TObject; Button: TMouseButton;
    Shift: TShiftState; X, Y: Integer);
    begin
      if Timer1.Enable then
      begin
        Timer1.Enabled := False;
        DoSomething;
      end;
    end;
    You'll have to play with the timer's interval property to set it to an appropriate length of time between the mousedown and the mouseup for the click, versus a mousedown, drag, mouseup.
    Last edited by majlumbo; September 5th, 2013 at 10:41 PM.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2013
    Posts
    1
    Rep Power
    0

    procedure on click


    Hi folks u can use this procedure TDiagramObject.FrameMouseDown(Sender: TObject; Button: TMouseButton;
    Shift: TShiftState; X, Y: Integer);
    const
    SC_DRAGMOVE = $F011;
    begin
    ReleaseCapture;
    Perform(WM_SYSCOMMAND, SC_DRAGMOVE, 0);
    end if
    end

IMN logo majestic logo threadwatch logo seochat tools logo