Jump to content
FabDev

Drag and drop component between applications

Recommended Posts

Hello,

 

I use Drag and Drop Component Suite  since a long time and its work fine.

But I don't know how to handle drag&drop between 2 VCL applications (same application execute at same time for example). But not file or URL just "common" Delphi components.

 

Just a TForm with a Tlabel. Tlabel.Drag :

 

Unit17.pas

unit Unit17;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;

type
  TForm17 = class(TForm)
    Label1: TLabel;
    procedure Label1DragOver(Sender, Source: TObject; X, Y: Integer; State: TDragState; var Accept: Boolean);
  private
    { Déclarations privées }
  public
    { Déclarations publiques }
  end;

var
  Form17: TForm17;

implementation

{$R *.dfm}

procedure TForm17.Label1DragOver(Sender, Source: TObject; X, Y: Integer; State: TDragState; var Accept: Boolean);
begin
 accept:=true;
 Showmessage('DragOVer from '+  Sender.name);
end;

end.

 

 

Unit17.dfm :

object Form17: TForm17
  Left = 0
  Top = 0
  Caption = 'Form17'
  ClientHeight = 347
  ClientWidth = 728
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'Tahoma'
  Font.Style = []
  OldCreateOrder = False
  OnCreate = FormCreate
  PixelsPerInch = 96
  TextHeight = 13
  object Label1: TLabel
    Caption = 'Drag Label'
    DragMode = dmAutomatic
  end
end

Between 2 components on the same form or application it's not a problem.

 

But execute 2 times this application : Drag&drop from label1 in application 1 to label1 in application 2 is not working...

 

How to handle drag&drop between this label in each running application ?
 

 

 

Edited by FabDev

Share this post


Link to post

The code you've shown is using VCL drag/drop. You can't use that to drag between applications.

 

What kind of data are you transferring?

 

If you just want to react to the action of dragging one label to another (in two different instances of the same application), then you can either register a custom clipboard format (see the CustomFormat examples) and drag that or you can just "misuse" the text format and drag some magic text string.

 

It's really very simple:

  1. Put a drop target and a drop source component on the form.
  2. Register the label as a drop target and do what ever you need to do in the OnDrop handler.
  3. In the label OnMouseDown handler use DragDetectPlus to detect the start of a drag and then initiate the drag on the drop source.
  4. If you don't want the user to be able to drag from and drop on the same label, then disable the drop target when you start the drag and enable it again when the drag is done.

If you can get 1-3 working within the application then it will also work between two different instances of that application.

Share this post


Link to post

Hello Anders,

 

First congratulation for your great component that I use since more than 10 years ! If you are a namesake 😉

 

This copy now :

https://github.com/landrix/The-Drag-and-Drop-Component-Suite-for-Delphi

 

My problem is that I need drag&drop from a grid to another grid in another different form. Each form are always shown in task bar using :

procedure TForm1.CreateParams(var Params: TCreateParams);
begin
  inherited;
  Params.ExStyle := Params.ExStyle and not WS_EX_APPWINDOW;
  Params.WndParent := Application.Handle;
end;

 

But when the second form is only visible in taskbar (in background or minimized for example) it's doesn't react at the drag&drop (when mouse is moved over the form button in task bar). The destination form doesn't come in foreground like an application do when it's detect drag&drop.

 

So I will try your solution....

Edited by FabDev

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×