TNGFileContentsFormat

<< Click to Display Table of Contents >>

Navigation:  Data Formats >

TNGFileContentsFormat

Previous pageReturn to chapter overviewNext page

TNGFileContentsFormat class implements common FILECONTENTS data format and allows to drag/receive virtual files created on-the-fly from any data stream. NG Drag&Drop use array of IStream type at the source side, and a special TNGFileContents record, which allows to query IStream for each file, at the target side. Please note that this format is specially designed to be used together with TNGFileDescriptorFormat format. While TNGFileDescriptorFormat format provide descriptions (like names, sizes, file dates and attributes) of dragging virtual files, this format provides data streams for dragging virtual files. please also note, that TNGFileContents record has no Count property, since the count of dragging files should be determined from the corresponding TNGFileDescriptorFormat data.

 

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.