Newsgroups : Borland : borland.public.delphi.nativeapi.win32 : 2005 Jul : Drag & drop files using an IDataObject
| Subject: | Drag & drop files using an IDataObject |
| Posted by: | "Bogdan Giusca" (gius..@gmail.com) |
| Date: | 11 Jul 2005 01:07:43 |
Hi. I want that my application to allow files dropped from Explorer in a Virtual Treeview (of Mike Lischke, latest version).
The VTV has an event which provides me an IDataObject with the information. I followed the docs from MSDN on what to do with it and came out with this code, but I get an access violation. (on the row marked with !!!!).
Any ideas how to fix it ? Thx.
procedure TfrmMain.vsDragDrop(Sender: TBaseVirtualTree; Source: TObject;
DataObject: IDataObject; Formats: TFormatArray; Shift: TShiftState;
Pt: TPoint; var Effect: Integer; Mode: TDropMode);
var medium:TStgMedium;
EnumFormat:IEnumFormatEtc;
format:TFormatEtc;
i, Fetched: integer;
buffer:array[0..100] of char;
name: pchar;
drop:Hdrop;
nfiles:UInt;
szFilename: pAnsiChar;
begin
if DataObject <> nil then
if succeeded(DataObject.EnumFormatEtc(DATADIR_GET, EnumFormat)) then
begin
EnumFormat.Reset;
while EnumFormat.Next(1, Format, @Fetched) = S_OK do
begin
GetClipboardFormatName(format.cfFormat, buffer, 100);
if buffer = 'FileName' then
begin
DataObject.GetData(format, Medium);
drop := hdrop(GlobalLock(Medium.hGlobal));
if drop <> 0 then
begin
nfiles := dragQueryFile(drop, $FFFFFFFF, szFilename, 255); //!!!!!
for i:= 0 to nfiles-1 do
begin
getmem(szfilename, MAX_PATH+1);
zeromemory(szfilename, MAX_PATH);
DragQueryFile(drop, i, szfilename, MAX_PATH);
showmessage(szFilename);
end;
GlobalUnlock(medium.hGlobal);
end;
ReleaseStgMedium(Medium);
end;
end;
end;
end;