If you want to store your own format in the clipboard, you need to use the setashandle and getashandle methods.
Setashandle (the format ID used for the clipboard, the memory handle of the data); the two parameters of this method are a bit troublesome.
You must use the registerclipboardformat function to customize the clipboard format. The second parameter is the memory handle rather than the memory address. Currently, I only know the functions globalalloc and globalrealloc that can allocate memory and return the handle, the gmem_ddeshare flag must also be used to allocate memory for the clipboard.
The getashandle (format ID used for clipboard) method returns the handle of the memory where the data is stored.
Obtain the memory address through the memory handle and use the globallock function.
In this example, the structure tmyrec is customized and the corresponding clipboard format cf_my is specified.
Unit unit1; interfaceuses windows, messages, sysutils, variants, classes, graphics, controls, forms, dialogs, stdctrls; Type tform1 = Class (tform) button1: tbutton; button2: tbutton; procedure formcreate (Sender: tobject); Procedure button1click (Sender: tobject); Procedure button2click (Sender: tobject); end; var form1: tform1; implementation {$ R *. DFM} uses clipbrd; Type tmyrec = Record Name: String [8]; age: byte; end; var cf_my: word; Procedure tform1.formcreate (Sender: tobject); begin cf_my: = registerclipboardformat ('My format'); end; Procedure tform1.button1click (Sender: tobject); var prec: ^ tmyrec; Data: thandle; Begin data: = globalalloc (gmem_ddeshare, sizeof (tmyrec); prec: = globallock (data); prec. name: = 'zhang san'; prec. age: = 99; globalunlock (data); clipboard. setashandle (cf_my, data); end; Procedure tform1.button2click (Sender: tobject); var prec: ^ tmyrec; Data: thandle; begin if not clipboard. hasformat (cf_my) Then exit; Data: = clipboard. getashandle (cf_my); prec: = globallock (data); showmessagefmt ('% S % d', [prec. name, prec. age]); {Zhang San 99 years old} globalunlock (data); end.
// This example forgets globalfree.