Newsgroups : Borland : borland.public.delphi.nativeapi.win32 : 2006 Nov : Using a custom format on the clipboard
| Subject: | Using a custom format on the clipboard |
| Posted by: | "Ronald Hoek - (Thuis)" ( |
| Date: | Thu, 9 Nov 2006 09:50:12 |
Hi,
I want to use a custom clipboard format so I can transfer data between two
different applications.
I'm using the following "unit" / funtions. In the initialisation of the unit
I register the custom clipboardformat.
At this point it goes wrong - Acces Violation at .... etc. !! <=== ERROR
I probebly need to do something special regaring Delphi-strings to put the
data on the clipboard!
==========================
unit ClipBrdTypeU;
interface
function XMLtoClipBoard(const aXML: string): boolean;
function ClipBoardToXML: string;
implementation
uses
SysUtils, Windows, ClipBrd, Forms;
type
TXMLData = record
CopyTime: TDateTime;
Data: string;
end;
var
_ClpFmt: Cardinal;
function XMLtoClipBoard(const aXML: string): boolean;
var
MemberHandle: THandle;
MemberPointer: ^TXMLData;
begin
Result := False;
if OpenClipboard(Application.Handle) then
try
EmptyClipboard;
MemberHandle := GlobalAlloc(GMEM_DDESHARE or GMEM_MOVEABLE,
SizeOf(TXMLData));
MemberPointer := GlobalLock(MemberHandle);
MemberPointer^.CopyTime := Now();
MemberPointer^.Data := aXML; <=== ERROR
GlobalUnLock(MemberHandle);
SetClipboardData(_ClpFmt, MemberHandle);
Result := True;
finally
CloseClipboard();
end;
end;
function ClipBoardToXML: string;
var
MemberInClip : THandle;
MemberPointer : ^TXMLData;
AMember : TXMLData;
begin
if Clipboard.HasFormat(_ClpFmt) and OpenClipboard(Application.Handle) then
try
MemberInClip := GetClipboardData(_ClpFmt);
MemberPointer := GlobalLock(MemberInClip);
with AMember do
begin
CopyTime := MemberPointer^.CopyTime;
Data := MemberPointer^.Data;
end;
GlobalUnLock(MemberInClip);
Result := AMember.Data;
finally
CloseClipboard();
end else
Result := '';
end;
initialization
_ClpFmt := RegisterClipboardFormat('SS_IE_DATA');
end.