<< Click to Display Table of Contents >> TNGFileContentsFormat |
|
The class declares two methods: Data and Ref. Data method can be used to drag virtual files at the source side, while Ref method can be used to receive files data data at the target side. NG Drag&Drop declares special type alias CF.FILECONTENTS to make user's code more readable:
SetLength(cnt, 1);
cnt[0] := TStreamAdapter.Create(MyFileStream, soOwned);
NGDropSource.Add(CF.FILEDESCRIPTOR.Data(...))
.Add(CF.FILECONTENTS.Data(cnt))
.Execute;
NGDropTarget.Register(MyTargetPanel, procedure(C: TNGTargetContext)
var
d: TNGFileArray;
cnt: TNGFileContents;
s: TStream;
begin
if C.Accept(CF.FILEDESCRIPTOR.Ref(@d)) and
C.Accept(CF.FILECONTENTS.Ref(@cnt)) then
begin
s := TOleStream.Create(cnt[0]);
ShowFileContent(s);
s.Free;
end;
end);
TStreamAapter standard Delphi class can be used to convert any usual TStream to OLE IStream. Please note, that the resulting IStream object is referenced by OLE and its actually unknown, when it will be released. So, its recommended to use soOwned value in the TStreamAapter constructor call to allow resulting IStream own initial TStream object.
To convert IStream back to TStream at the target side, TOleStream standard Delphi class can be used.