Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TDropFileTarget.MultiTarget fails in some cases #67

Open
PeterPanino opened this issue Apr 4, 2023 · 4 comments
Open

TDropFileTarget.MultiTarget fails in some cases #67

PeterPanino opened this issue Apr 4, 2023 · 4 comments

Comments

@PeterPanino
Copy link

PeterPanino commented Apr 4, 2023

I use the TDropFileTarget 5.82 component in Delphi 11.3. I have activated the MultiTarget property and registered six different controls as Target in the form's OnCreate event handler. The Register action doesn't always work for all registered controls, as sometimes, randomly, one of the registered controls does not work as a drop target. Therefore, feedback should be given on whether the Register action fails on a control. The Register procedure should be a function and give back the Register result. Or a parameter that holds the registration success?
Also, sometimes the OnDragOver event handler is not called on some registered controls.

@landrix
Copy link
Owner

landrix commented Apr 4, 2023

What type are the controls? Do you have an example?

@PeterPanino
Copy link
Author

These are the controls:

DropFileTargetMulti.Register(dxPDFViewerMain); // TdxPdfViewer
DropFileTargetMulti.Register(PlainTextEditor); // TImageEnFolderMView
DropFileTargetMulti.Register(ImageEnFolderMViewBrushImages); // TJamFileList
DropFileTargetMulti.Register(JamFileListPDFAttachments); // TJamFileList
DropFileTargetMulti.Register(ImageEnViewPixelEditor); // TImageEnView
DropFileTargetMulti.Register(TextEditorSVG); // TTextEditor

@PeterPanino
Copy link
Author

Also, I need to check the file in OnDragOver;

procedure TformMain.DropFileTargetMultiDragOver(Sender: TObject; ShiftState: TShiftState; APoint: TPoint; var Effect: Integer);
begin
  CodeSite.Send('Test', DropFileTargetMulti.Files[0]);
end;

But the OnDragOver event handler is not executed!

@andersmelander
Copy link

Therefore, feedback should be given on whether the Register action fails on a control.

An exception is raised in the registration fails:

OleCheck(RegisterDragDrop(Parent.Handle, TCustomDropTarget(Owner)));

What you're likely experiencing is that the control handle is being destroyed and recreated after you have registered the control as a drop target. For example, this happens if you change the FormStyle of a form.

The drop target component works around this via the AutoRegister property. What AutoRegister does is that it instructs the drop target component to create a hidden child control with your drop target as the parent. Now if the handle of the drop target is recreated the child control will be notified and it will automatically redo the drop target registration (the call to RegisterDragDrop). See TWinControlProxy
So make sure AutoRegister=True. If your target is a RichEdit control (or if it's based on a RichEdit control) then you're out of luck with regard to AutoRegister because they don't play well together.

If AutoRegister is already True then something else is going on. It could be that the controls are doing their own drop target registration, or that they are messing with their child controls (and thus the TWinControlProxy).

But the OnDragOver event handler is not executed!

Try running the TargetAnalyzer. It will show you how your application is interacting with the drop source.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants