Help needed! pastespecial like "drag and drop"

General TRichView support forum. Please post your questions here
Post Reply
lovethisgame
Posts: 8
Joined: Sat Sep 13, 2008 1:36 am

Help needed! pastespecial like "drag and drop"

Post by lovethisgame »

I want to start a function like "PasteSpecial", but now I have a problem. The code is as follows:
--------------------------

Code: Select all

procedure TForm1.RichViewEdit1OleDrop(Sender: TCustomRichView;
  const DataObject: IDataObject; Shift: TShiftState; X, Y: Integer;
  PossibleDropEffects: TRVOleDropEffects; var DropEffect: TRVOleDropEffect;
  var DoDefault: Boolean);
var
  Data: TRVAnsiString;
  ptr: Pointer;
  Medium: TStgMedium;
  FmtEtc: TFormatEtc;
  Enum: IEnumFormatEtc;
begin
 DoDefault:=False;
 FmtEtc.ptd := nil;
 FmtEtc.dwAspect := DVASPECT_CONTENT;
 FmtEtc.lindex := -1;
 FmtEtc.tymed := TYMED_HGLOBAL;
  OleCheck(DataObjECT.EnumFormatEtc(DATADIR_GET, Enum));
  while Enum.Next(1, FmtEtc, nil) = S_OK do
   begin
     try
     OleCheck(DataObject.GetData(FmtEtc, Medium));
     Assert(Medium.tymed = FmtEtc.tymed);
     SetLength(Data, GlobalSize(Medium.hGlobal));
     ptr := GlobalLock(Medium.hGlobal);
     Move(ptr^, PRVAnsiChar(Data)^, Length(Data));
     OpenClipboard(0);
        SetClipboardData(FmtEtc.cfFormat,Medium.hGlobal);
        CloseClipboard;
     finally
       GlobalUnlock(Medium.hGlobal);
        ReleaseStgMedium(Medium);
     end;



  end;

rvActionPasteSpecial1.Execute;


end;
What I want to do is :
1, place the data from IDataObject onto the clipboard in the specific format.
2, execute the rvActionPasteSpecial.

But when i run the demo application, sometimes the data placed on the clipboard will be invalid. For example, when i drag something from Word 2010 or FireFox. But the data in some other formats are accessible.
I have also tried "OleSetClipboard", the result is all the data are unaccessible.

Any kind of suggestions and solutions are appreciated.
Thanks again.
Post Reply