问题
I am trying to make a chessboard gui in DelphiXE4 with TRectangle & TText using unicode chess pieces (see StackOverflow Delphi chess unicode linkand drag and drop but I cannot get DND to work properly! My test project is FireMonkey FMX. I have tried various code additions to DragDrop/DragOver Events including using Accept & Source in code but to no result.
I set dragdrop to auto on TRectangle & TText components & can get drag function but no drop function! What code do I need to enter in Events DragDrop DragOver on target TRectangle to accept the drop event? (I am very confused with this & cannot find clear instruction on Google search anywhere!)
Here is my basic test code (on 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.
Most grateful for help & look forward to replies-thanks
EDIT/UPDATE
Here is 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 aaargh!
回答1:
You will have to Accept if the Source of then TDragObject is TText.
Accept := Data.Source is TText;
Sender would be your Rectangle7, or any component Rectangle7DragOver is assigned to.
来源:https://stackoverflow.com/questions/17232577/drag-and-drop-unicode-ttext-in-delphixe4