delphi6時代に作ったOLD DragDropをXE2に移植しました。
Unicode以前は自分の中のDragDropでも、IEなど外からのDropでも正常に機能していましたが、 XE2にしたら自分のDragDropは成功しますがIEからDROPは文字化けしてしまいます。
下のコードのOLEDropTextですが「テキスト」という文字をMyEditの中でDragDropすると①のところで
Bufferに「テキスト」が入りますが、IEから「テキスト」をMyEditにDropすると「斃䲃境枃꬀ꮫꮫꮫﺫﻮﻮﻮ」となります。
②のBufferには、自己Dropでは「ニ0ュ0ケ0ネ0」になってしまいますがIEからだと「テキスト」が入ります。ただしサロゲートは当然文字化けです。
procedure TMyEdit.OleDragDrop(const DataObj: IDataObject; KeyState: Longint; Point: Tpoint; var Effect: Longint);
var
res,i: integer;
Medium: TStgMedium;
hBuf:THandle;
begin
for i := 0 to FDropTarget.FormatList.Count - 1 do
begin
if DataObj.GetData(FDropTarget.FormatList.Formats[I], Medium) = S_OK then
begin
try
case FDropTarget.FormatList.Formats[I].cfFormat of
CF_HDROP:
OLEDropFiles(Medium.hGlobal);
CF_TEXT:
begin
OLEDropText(Medium.hGlobal,Point);
end;
end;
finally
ReleaseStgMedium(Medium);
end;
Break;
end;
end;
end;
//テキストを取り出す
procedure TMyEdit.OLEDropText(Drop: HGLOBAL; Point: Tpoint);
var
Buffer: String;
pData: PChar;
begin
pData := GlobalLock(Drop);
try
Buffer:=StrPas(pData);//①
Buffer:=WideString(AnsiString(PAnsiChar(pData))) ;//②
finally
GlobalUnlock(Drop);
end;
end;
ツイート | ![]() |