I was able to get this working. Using the TImageEnFolderMView code for some guidance and the drag and drop file demo.
Below code what I came up with to handle my situation, with the file name fixing.
Made it an object to create for this.
To help make this a bit easier to apply to other exact same situations, as I have
a number of places to apply this.
Not sure if best way to go about this, but .. it works?
unit Unit87;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs,
System.types,
hyiedefs, hyieutils, iexBitmaps, iesettings, iemio, ieview, iemview, iexFolderMView,
iexWindowsFunctions, Vcl.StdCtrls;
type
TImageDragAndDropHelper = class
private
fDragging: boolean;
fMouseClickPos: tpoint;
fMouseClickTime: cardinal;
fLastDragTime: cardinal;
fDragDrop: TIEFileDragDrop;
fImage: TImageEnMView;
public
constructor Create;
destructor Destroy; override;
procedure setMouse(Button: TMouseButton; X, Y: Integer);
procedure CheckDrag(X, Y: Integer);
property Image : TImageEnMView read fImage write fImage;
end;
TForm87 = class(TForm)
Image_inventory: TImageEnMView;
procedure FormCreate(Sender: TObject);
procedure Image_inventoryMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
procedure Image_inventoryMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
private
public
dragImage: TImageDragAndDropHelper;
end;
var
Form87: TForm87;
implementation
{$R *.dfm}
Constructor TImageDragAndDropHelper.Create;
begin
inherited;
fDragging := false;
fMouseClickTime := 0;
fLastDragTime := 0;
fDragDrop := nil;
end;
Destructor TImageDragAndDropHelper.Destroy;
begin
if assigned(fDragDrop) then
fDragDrop.free;
inherited;
end;
procedure TImageDragAndDropHelper.setMouse(Button: TMouseButton; X, Y: Integer);
begin
fDragging := Button = mbLeft;
fMouseClickPos := point(X, Y);
fMouseClickTime := GetTickCount();
end;
procedure TImageDragAndDropHelper.CheckDrag(X, Y: Integer);
const
MS_Before_Drag = 333;
var
ssFilenames: TStringList;
fileIDX: Integer;
idx: Integer;
begin
if not assigned(fImage) then // no reason to run if not assigned yet
exit;
idx := fImage.ImageAtPos(fMouseClickPos.X, fMouseClickPos.Y, true);
if (fDragging) and (GetTickCount() - fMouseClickTime > MS_Before_Drag) and (idx > -1) and
((Abs(X - fMouseClickPos.X) >= Mouse.DragThreshold) or (Abs(Y - fMouseClickPos.Y) >= Mouse.DragThreshold)) then
begin
fDragging := false;
fImage.Perform(WM_LBUTTONUP, 0, MakeLong(X, Y));
ssFilenames := TStringList.Create;
try
fImage.SelectedFilenames(ssFilenames);
if ssFilenames.Count > 0 then
begin
// we have image set that have pre-built thumbnails
// we show only the thumbnail in the TImageEnMView
// but we really want to drag the fullsize image
// downside is, the chances the full image does not exist
// in our production code, it populates thumbnails only if fullsize image file exists
// so the chance it was removed since then is slim but could happen.
for fileIDX := 0 to ssFilenames.Count - 1 do
ssFilenames[fileIDX] := stringreplace(ssFilenames[fileIDX], '_thumb', '', [rfignorecase]);
// if becomes a problem, can add an option to double check and remove from ssFilenames any file
// that does not exist. Right now not going to since network drivers are slow
// and need this to be fast
// worse case, will add it and just have to deal with it
if fDragDrop = nil then
fDragDrop := TIEFileDragDrop.Create(nil); // we just need to create it. No events needed
fDragDrop.ShowPreview := true;
fDragDrop.PreviewWidth := fImage.ThumbWidth;
fDragDrop.PreviewHeight := fImage.ThumbHeight;
fDragDrop.InitiateDragging(ssFilenames, [iedaCopy, iedaMove]);
end;
finally
ssFilenames.free;
end;
end;
end;
procedure TForm87.FormCreate(Sender: TObject);
begin
Image_inventory.fillfromdirectory('c:\cmis\2025\2025', -1, true);
dragImage := TImageDragAndDropHelper.Create;
dragImage.fImage := Image_inventory;
end;
procedure TForm87.FormDestroy(Sender: TObject);
begin
dragImage.free;
end;
procedure TForm87.Image_inventoryMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
dragImage.setMouse(Button, X, Y);
end;
procedure TForm87.Image_inventoryMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
begin
dragImage.CheckDrag(X, Y);
end;
end.