Drag Unicode TText to DelphiXe4

I am trying to make a chess gui in DelphiXE4 with TRectangle and TText using unicode chess pieces (see https : //stackoverflow.com/a/167014/... and drag, but I can’t get DND working correctly! My test project is FireMonkey FMX. I I tried various code additions to the DragDrop / DragOver events, including the use of Accept and Source in the code, but without result.

I set dragdrop to auto on the TRectangle and TText components and can get a drag function, but not a drop function! What code do I need to enter in Events DragDrop DragOver in the destination TRectangle in order to receive the drop event? (I am very confused by this and cannot find clear search instructions anywhere!)

Here is my basic test code (in form):

unit Unit1; interface uses System.SysUtils, System.Types, System.UITypes, System.Rtti, System.Classes, System.Variants, FMX.Types, FMX.Controls, FMX.Forms, FMX.Dialogs, FMX.StdCtrls, FMX.Objects; type TForm1 = class(TForm) Rectangle1: TRectangle; Rectangle2: TRectangle; Rectangle3: TRectangle; Rectangle4: TRectangle; Rectangle5: TRectangle; Rectangle6: TRectangle; Rectangle7: TRectangle; Rectangle8: TRectangle; Rectangle9: TRectangle; Text1: TText; procedure Rectangle7DragOver(Sender: TObject; const Data: TDragObject; const Point: TPointF; var Accept: Boolean); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.fmx} procedure TForm1.Rectangle7DragOver(Sender: TObject; const Data: TDragObject; const Point: TPointF; var Accept: Boolean); begin if Sender is TText then Accept := True; end; end. 

I am very grateful for the help and I look forward to hearing from you - thanks

EDIT / UPDATE

Here is the code from bummi:

 unit Unit3; interface uses System.SysUtils, System.Types, System.UITypes, System.Rtti, System.Classes, System.Variants, FMX.Types, FMX.Controls, FMX.Forms, FMX.Dialogs, FMX.Objects, FMX.Edit; type TForm3 = class(TForm) Rectangle1: TRectangle; Text1: TText; Edit1: TEdit; procedure Rectangle1DragOver(Sender: TObject; const Data: TDragObject; const Point: TPointF; var Accept: Boolean); private { Private-Deklarationen } public { Public-Deklarationen } end; var Form3: TForm3; implementation {$R *.fmx} procedure TForm3.Rectangle1DragOver(Sender: TObject; const Data: TDragObject; const Point: TPointF; var Accept: Boolean); begin Caption := Data.Source.ClassName ; Accept := Data.Source is TText; end; end. 

However, even with this, I still cannot get my chess example to work for me! Oh dear aaarch!

+1
source share
1 answer

You will need to accept if the source of the TDragObject is TText.

  Accept := Data.Source is TText; 

The sender is your Rectangle7, or any Rectangle7DragOver component is assigned.

+2
source

Source: https://habr.com/ru/post/1487016/


All Articles