delphi
编程技巧
源代码在线查看: clipboard的应用 (2001年5月3日).txt
clipboard的应用 (2001年5月3日)
网友更新 分类:数据库 作者: qiubole(推荐) 推荐:qiubole 阅读次数:195
(http://www.codesky.net)
--------------------------------------------------------------------------------
unit clip;
interface
uses
sysutils,windows,clipbord;
const
ddgdata='BOLE_DDG';
type
TDATARect=packed record
LName:string[10];
FName:string[10];
MI:string[2];
Age:integer;
Birthdate:TDatatime;
end;
Tdata=class
public
Rec:TDataRec;
procedure Copytoclipboard;
procedure getfromclipboard;
end;
var cf_ddgdata:word;
implementation
procedure tdata.copytoclipboard;
const
crlf=#13#10;
var
data:thandle;
dataptr:pointer;
tempstr:string[50];
begin
data:=globalalloc(gmem_moveable,sizeof(tdatarect));
try
dataptr:=globallock(data);
try
move(rec,dataptr^,sizeof(tdatarec));
clipboard.open;
clipboard.setashandle(cf_ddgdata,data);
with rec do
tempstr:=fname+crlf+lname+crlf+mi+crlf+inttostr(age)+crlf+datatimetostr(birthdate);
clipboard.astext:=tempstr;
clipboard.close;
finally
globalunlock(data);
end;
except
globalfree(data);
raise;
end;
end;
procedure tdata.getfromclipboard;
var
data:thandle;
dataptr:pointer;
size:integer;
begin
data:=clipboard.getashandle(cf_ddgdata);
if data=0 then exit;
dataptr:=globallock(data);
try
if sizeof(tdatarec)>globalsize(data) then
size:=globalsize(data)
else
size:=sizeof(tdatarec);
mov(dataptr^,rec,size);
finally
global(unlock(data);
end;
end;
initialization
cf_ddgdata:=registerclipboard(format(ddgdata));
end;
以上的tdatarec可以改成需要的结构。