procedure CopyFilesToClipboard(FileList:
string);
{Achtung: Dateien mit einem #0 trennen!
Beispiel:
procedure TForm1.Button1Click(Sender: TObject);
begin
CopyFilesToClipboard('C:\Bootlog.Txt'#0'C:\AutoExec.Bat');
end;}
var
DropFiles: PDropFiles;
hGlobal: THandle;
iLen: Integer;
begin
FileList := FileList + #0#0;
iLen := Length(FileList) * SizeOf(Char);
hGlobal := GlobalAlloc(GMEM_SHARE
or GMEM_MOVEABLE
or GMEM_ZEROINIT, SizeOf(TDropFiles) + iLen);
if hGlobal = 0
then
raise Exception.Create('
Could not allocate memory.');
DropFiles := GlobalLock(hGlobal);
DropFiles.pFiles := SizeOf(TDropFiles);
DropFiles.fWide := SizeOf(Char) <> 1;
Move(FileList[1], (PAnsiChar(DropFiles) + SizeOf(TDropFiles))^, iLen);
GlobalUnlock(hGlobal);
Clipboard.SetAsHandle(CF_HDROP, hGlobal);
end;
procedure CopyFilesToClipboard(FileList: TStrings);
var
LB:
string;
begin
LB := FileList.LineBreak;
try
FileList.LineBreak := #0;
CopyFilesToClipboard(FileList.Text);
finally
FileList.LineBreak := LB;
end;
end;