Drag Firemonkey controls at runtime - how to?

I would like to be able to drag controls around at runtime. e.g., a rectangle or panel using teh mouse - move it from one location to another

With VCL I would use something like this

http://delphi.about.com/library/weekly/aa102505a.htm

 if   (Sender is TWinControl) then
  begin
    inReposition:=True;
    SetCapture(TWinControl(Sender).Handle);
    GetCursorPos(oldPos);
  end;

However, I am completely stuck on how to do similar in firemonkey - I know it is a long shot being so new and all but anyone out there point me the right direction?
0
Ralph
9/3/2011 9:50:00 AM
embarcadero.delphi.firemonkey 4901 articles. 4 followers. Follow

5 Replies
4039 Views

Similar Articles

[PageSpeed] 52
Get it on Google Play
Get it on Apple App Store

OK, I have a kind of a work-around using mousedown and mouseup and moving the components that way. However, not a nice solution.
0
Ralph
9/4/2011 1:20:30 AM
> {quote:title=Ralph Wesseling wrote:}{quote}
> OK, I have a kind of a work-around using mousedown and mouseup and moving the components that way. However, not a nice solution.

Hi Ralph
Mind sharing your workaround? I also need to move my controls at runtime and have not found the way to accomplish this in FM. 
Setting Dragmode to auto lets me move a button but I can't find a way to leave the control at the 'dragged-to' position.
Thanks

Al
0
Alan
11/6/2011 1:12:26 AM
> {quote:title=Alan White wrote:}{quote}
> > {quote:title=Ralph Wesseling wrote:}{quote}
> > OK, I have a kind of a work-around using mousedown and mouseup and moving the components that way. However, not a nice solution.
> 
> Hi Ralph
> Mind sharing your workaround? I also need to move my controls at runtime and have not found the way to accomplish this in FM. 
> Setting Dragmode to auto lets me move a button but I can't find a way to leave the control at the 'dragged-to' position.
> Thanks
> 
> Al

Hi all!
I want to use drag and drop within the program.
I must have the ability to assign components to drag, and others to take. How to implement it?
Drag and drop components to dynamically created.
0
Serge
6/18/2012 2:37:28 AM
> {quote:title=Ralph Wesseling wrote:}{quote}
> I would like to be able to drag controls around at runtime. e.g., a rectangle or panel using teh mouse - move it from one location to another
> 
> With VCL I would use something like this
> 
> http://delphi.about.com/library/weekly/aa102505a.htm
> 
>  if   (Sender is TWinControl) then
>   begin
>     inReposition:=True;
>     SetCapture(TWinControl(Sender).Handle);
>     GetCursorPos(oldPos);
>   end;
> 
> However, I am completely stuck on how to do similar in firemonkey - I know it is a long shot being so new and all but anyone out there point me the right direction?

I have just come across the same issue.  I think I have solved it, at least in a simple example.

FMX controls now have an IRoot interface, exposed through their Root property.  IRoot.Captured should be set to the control that you want to capture mouse events.
For example, to use a TLine as a splitter you might want to be able to drag it and setting the Root.Capture property to the TLine seems easier than using the built in drag and drop in FMX.

procedure TForm1.SplitterMouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Single);
begin
  Splitting := True;
  SplitStart := X;
  (Sender as TLine).Root.Captured := (Sender as TControl);
end;

The OnMouseDown event of the TLine sets the TLine.Root to the line itself, so the line keeps getting OnMouseMove events even when the mouse leaves the line's extent.

procedure TForm1.SplitterMouseUp(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Single);
begin
  Splitting := False;
  (Sender as TLine).Root.Captured := nil;
end;

The OnMouseUp event removes the capture control.  I am not sure this is absolutely necessary - it may happen automatically, as the application seems to work if you omit this step.

procedure TForm1.SplitterMouseMove(Sender: TObject;
  Shift: TShiftState; X, Y: Single);
begin
  X :=  X - SplitStart;     // in local coords  how far mouse has moved horizontally
  if Splitting and (Abs(X) > 0.9) then  // want to move at least one pixel left or right
  begin
    SplitterPosition := SplitterPosition + X;  // adjust position - the property setter for SplitterPosition can move the line (i.e. you do a drag that works)
    // Now do something else if you need to....

  end;
end;

The OnMouseMove event for the TLine, in this example, moves the line itself using the SplitterPosition property.  This example just drags a Tline horizontally, but you should be able to adapt it for general control dragging.

Hope this helps
0
Steve
10/11/2013 11:19:48 AM
> {quote:title=Ralph Wesseling wrote:}{quote}
> I would like to be able to drag controls around at runtime. e.g., a rectangle or panel using teh mouse - move it from one location to another

Actually you can use a control TSelection, which is extremely useful. 
You needed just place your control inside TSelection (make TSelection as a parent), make aling=client and lock your control. The rest was done by TSelection. When you are finished with moving and sizing, you need to unlock control, make align=none, and restore previous parent of your control and copy position of TSelection to your control.
1
Dmitry
10/15/2013 9:44:27 AM
Reply:

Similar Artilces:

Ann: FastReport FMX for Delphi XE3 (FireMonkey 2) and XE2 (FireMonkey) released
Dear friends, Visual report designer is available now on both MS Windows and MAC OS X! Full sources. We can write here full list of possibilities, but it will so long. Let see FastReport VCL and FastReport FMX comparison table: http://www.fast-report.com/en/products/comparison-fast-report-firemonkey-vcl.html And all of this - just now in your hands for business-applications for Mac. Report generator FastReport FMX is the first multiplatform solution for including Business Intelligence into software based on Embarcadero FireMonkey IDE (Delphi for MS Windows and Apple Mac OS X)...

Ann: X-platform report generator for Delphi XE3 (FireMonkey 2) and XE2 (FireMonkey) released
Dear friends, Visual report designer is available now on both MS Windows and MAC OS X! Full sources. We can write here full list of possibilities, but it will so long. Let see FastReport VCL and FastReport FMX comparison table: http://www.fast-report.com/en/products/comparison-fast-report-firemonkey-vcl.html And all of this - just now in your hands for business-applications for Mac. Report generator FastReport FMX is the first multiplatform solution for including Business Intelligence into software based on Embarcadero FireMonkey IDE (Delphi for MS Windows and Apple Mac OS X)...

XE3 Firemonkey Controls Demo
Hi, I am evaluating XE3 and been playing about with the Controls Demo. For some reason I can not get the Drag and Drop component on the ExtCtrls tab to work. Is it meant to accept files from Windows Explorer / Finder ? If so, it's not. When I was using Delphi 7 back in the day I used a component set from Melander that allowed me to drop my files from Windows Explorer onto my programs. Obviously I can not use that component set any more because it was using Windows Messages and these do not work in the Firemonkey set. Does anyone have a tutorial on how to implement Drag and Drop ...

Delphi / FireMonkey release components created at runtime [Edit]
Hello, XE6, Win7 Am I right I thinking that if I create a component, such as TImage, at runtime, Delphi automatically releases the memory when the program closes. I declared this: im: TImage; as a TForm variable. Put this in .FormCreate: ReportMemoryLeaksOnShutdown := DebugHook <> 0; This picks up things like TStrokeBrush when I don't run .Free; I then put this in: procedure TFrmScales.Button4Click(Sender: TObject); begin im := TImage.Create(self); im.Bitmap.Assign(I_note.Bitmap); // I_note is a TImage that I put there at design-time im.Pa...

Firemonkey
I am so dammed frustrated with firemonkey and livebindings. The VCL + DB Controls were fast, consistent, and stable. This fmx framework is crap. It's slow on my i5 Macbook. I'd be embarrassed to put out an app like this. The help is lousy and apparently very few people are using it based on my failed Google searches. I can see why. Livebindings is cute when you have a few fields, but it a rats nest when you have a moderately complex form and have to wire up dozens of controls. There is no official support for nullable fields in livebindings which blows my mind....

Delphi XE 7 UPDATE 1 FireMonkey, Drag & Drop Files... how?
I have an app and want to add drag and drop files support, i try this code for example: {code} procedure TForm1.Grid1DragDrop(Sender: TObject; const Data: TDragObject; const Point: TPointF); begin caption := data.Files[0]; end; procedure TForm1.Grid1DragOver(Sender: TObject; const Data: TDragObject; const Point: TPointF; var Operation: TDragOperation); begin operation := TDragOperation.Link; end; {code} and work correctly in a new proyect, but if i implement this in an exisiting proyect this no work :( what happen? how make this work? thanks and sorry for my en...

Delphi XE 7 UPDATE 1 FireMonkey, Drag & Drop Files... how?
I have an app and want to add drag and drop files support, i try this code for example: {code} procedure TForm1.Grid1DragDrop(Sender: TObject; const Data: TDragObject; const Point: TPointF); begin caption := data.Files[0]; end; procedure TForm1.Grid1DragOver(Sender: TObject; const Data: TDragObject; const Point: TPointF; var Operation: TDragOperation); begin operation := TDragOperation.Link; end; {code} and work correctly in a new proyect, but if i implement this in an exisiting proyect this no work :( what happen? how make this work? thanks and sorry for my en...

Installing components for FireMonkey HD and FireMonkey iOS
Hi, How do I install components for both FireMonkey HD and FireMonkey iOS? I have one package 'FMXMyFireMonkeyControl' and 'FMIFireMonkeyControl' which both point to the same file with the same registration 'TFireMonkeyControl'. If I compile one package (FMXMyFireMonkeyControl) it installs correctly, then change the include file (FMCompile.INC) to compile for IOS (FMIFireMonkeyControl) which is included in the FMX.FireMonkeyControl.pas file: {$I FMCOMPILE.INC} uses {$IFDEF COMPILEIOS} FMX_Types, FMX_Objects, FMX_Forms, FMX_Dialogs, FMX_Effe...

Virtual Controls in FireMonkey
What are the fireMonkey controls that support UI virtualisation > {quote:title=vikosh maha wrote:}{quote} > What are the fireMonkey controls that support UI virtualisation As of XE2 the TGrid is the only one I know of (certainly TListBox and TTreeView don't). I haven't investigated XE3 far enough yet to give an answer. ...

Drag Control in Control
hi, is there a possibility to create a server control that allows dragging other controls into it and displaying the whole package fully rendered in design time?regardsAlex Yeah - you mean a templated control... the built in repeater has this, right click, choose edit template, and then drag and drop all the controls you want On the template editing surface you see the default stuff the control renders Once your done, right click and exit template editing mode Data bound templated controls are a little trickier Its a little tricky because you have to do some data source i...

Serial Port Controlling in Firemonkey?
Hi, What kind of path should I follow to make my application requires serial port communication compatiable with windows and Mac OS enviorement? Thanks. ...

Change a control matrix in firemonkey
Hi every I have a TRectangle and a TMatrix3x2F i managed to copy the Matrix values from the rectangle.AbsoluteMatrix to TMatrix3x2F like this: {code} void TForm1::GrabRectMatrix() { Matrix3x2F FTransform; FTransform._11 = Rect1->AbsoluteMatrix.m11; FTransform._12 = Rect1->AbsoluteMatrix.m12; FTransform._21 = Rect1->AbsoluteMatrix.m21; FTransform._22 = Rect1->AbsoluteMatrix.m22; FTransform._31 = Rect1->AbsoluteMatrix.m31; FTransform._32 = Rect1->AbsoluteMatrix.m32; } //--------------------------------------------------------------------------- {code} ...

How to drag an image from Explorer to Firemonkey
Is it possible to drag an image from explorer onto a Firemonkey TImage. Would any solution also work in Mac OS or would one need to implement two different processes for different OS Bennie > {quote:title=Bennie Coetzer wrote:}{quote} > Is it possible to drag an image from explorer onto a Firemonkey TImage. > Would any solution also work in Mac OS or would one need to implement two different processes for different OS > Bennie You might be interested in this: https://forums.embarcadero.com/thread.jspa?messageID=405188 I have it running in FM with the mod made to the s...

Native OS Controls for Firemonkey
I've just launched a Kickstarter project to build a Native OS control framework and component set for Firemonkey. NakeyMonkey is first a set of base components and interfaces that simplify wrapping native OS controls in a cross-platform way allowing them to be write-once, cross-compile. By providing a base component to descend native wrappers from and a base platform object for implementing the OS specific implementation, NakeyMonkey allows components like a RichEdit to be available to your Firemonkey apps without having to rewrite the entire implementation of parsing rich text tags a...

Web resources about - Drag Firemonkey controls at runtime - how to? - embarcadero.delphi.firemonkey

Firemonkeys - GamesIndustry International
The world's leading games industry website. Get insight from todays industry leaders with news, interviews and analysis of global gaming trends. ...

Firemonkey’s Real Racing 3 To Launch At The End Of February
In September, Apple demoed Firemonkey’s Real Racing 3 at the iPhone 5 event . Three months later and the game has yet to show up in the App Store. ...

EA Games and Firemonkey Bringing Real Racing 3 to Android, Fasten your Seat Belts
Start up your engines race fans, EA Games is teaming up with Firemonkey to bring Real Racing 3 to mobile devices. If you’re a fan of more realistic ...

EA's Firemint and IronMonkey Studios Merge to Become FireMonkeys
... game development studios into one mega-studio in Australia. Firemint and IronMonkeys will be merged into a single studio now known as Firemonkeys ...

News: Firemonkeys announces Real Racing 3
Firemonkeys, a new gaming subsidiary of Electronic Arts born from the merger of FireMint and IronMonkey, has announced the coming release of ...

firemonkeys - iMore
EA has pushed out another impressive update to its equally impressive iOS racer, Real Racing 3, that for the first time brings cars from Ferrari ...

Firemonkeys on Real Racing 3 going free-to-play
... got a hands-on preview of Real Racing 3. We also spoke with Ptolemy Oberin, one of the game’s programmers and project lead at developer Firemonkeys, ...

Real Racing 3 coming in 2012 from Firemonkeys
The first game from recently merged developer Firemonkeys is Real Racing 3 , the developer revealed moments ago during EA's Summer Showcase event ...

Firemonkeys Previews Real Racing 3 for iPhone and iPad
Firemonkeys, the new combined studio from EA combining the IronMonkey and Firemint gaming studios, has announced the development of Real Racing ...

EA Mobile Moves: IronMonkey & Firemint Merge Into “Firemonkeys,” Now Have 50M Players Between
... that it is merging two top mobile game studios, IronMonkey and Firemint , which will fittingly combine to create a new company, called Firemonkeys. ...

Resources last updated: 1/21/2016 11:47:48 PM