Custom Formats

<< Click to Display Table of Contents >>

Navigation:  Data Formats >

Custom Formats

Previous pageReturn to chapter overview

NG Drag&Drop provides the ability to declare custom data formats. This feature can be used to implement application's private drag&drop formats or to implement missing commonly used formats.

 

An easy way to declare custom format based on some predefined format is to use CustomFormatAttribute attribute. A custom format should have its own unique name, which is used to register the format in the system:

 

type

  [CustomFormat('My Unique Format Name')]

  TMyFormat = class(TNGTextFormat);

 

That it! The custom format is declared. And so, it can be used like any other data format:

 

NGDropSource.Add(TMyFormat.Data('My dragging text'))
            .Execute;
 
NGDropTarget.Register(MyTargetPanel, procedure(C: TNGTargetContext)
var
  s: AnsiString;
begin
  if C.Accept(TMyFormat.Ref(@s)) then
    Edit1.Text := string(s);
end);

 

Advanced users can also implement custom formats descending the class directly from TNGDataFormat base class, just like built-in formats are implemented. This way the user have to deal with some low-level OLE drag&drop stuff, for example, TStgMedium and TFormatEtc WinAPI structures, which are out of current documentation scope. The source code in NG.DragDrop.Formats.pas unit, where all built-in formats are declared can be used as a reference implementation.