OK, I will study the drag and drop demo.
There are lots of code comments to help explain the code. If you have any further questions, don't hesitate to ask here (or preferably in the official fpGUI support newsgroup).
In summary, fpGUI's drag-n-drop is pretty straight forward. A form has a
DNDEnabled property that must be set to True to enable DND for that form. Each widget has the following properties:
AcceptDrops: boolean
OnDragEnter
OnDragLeave
OnDragDrop
OnDragStartDetected
Those should be pretty self explanatory. DND data is sent around inside a
TfpgDrag instance and normally uses mime types to identify different types of data. The receiving widget will check the available mime types and then decide if it will accept the drop or not.
Here is an example
OnDragStartDetected event handler that initiates a DND action. This example comes from the DND example included with fpGUI. For your own applications or internal DND actions, you can define your own mime types - it's just a string type.
procedure TMainForm.LabelDragStartDetected(Sender: TObject);
var
m: TfpgMimeData;
d: TfpgDrag;
begin
m := TfpgMimeData.Create;
{ via convenience properties }
m.Text := 'My name is Earl';
m.HTML := 'My name is <b>Earl</b>';
{ Could also have used the generic SetData function }
// m.SetData('text/plain', 'My name is Earl');
// m.SetData('text/html', 'My name is <b>Earl</b>');
{ tell TfpgDrag who is the Source of the drag }
d := TfpgDrag.Create(Sender as TfpgWindow);
{ TfpgDrag now takes ownership of TfpgMimeData }
d.MimeData := m;
{ TfpgDrag instance will be freed later when DND action is completed }
d.Execute([daCopy]);
end;
Here is an example of a
OnDragEnter event handler. In this example, the widget only accepts data with the mime type 'text/plain'.
procedure TMainForm.Edit1DragEnter(Sender, Source: TObject;
AMimeList: TStringList; var AMimeChoice: TfpgString;
var ADropAction: TfpgDropAction; var Accept: Boolean);
var
s: string;
begin
ShowMimeList(AMimeList);
s := 'text/plain';
if chkAccept.Checked then
Accept := False
else
Accept := AMimeList.IndexOf(s) > -1;
if Accept then
begin
if AMimeChoice <> s then
AMimeChoice := s;
end;
end;