unit ClipboardFormatUnit;

interface

uses
 Clipbrd, Windows, SysUtils;

type
  PLineData=^TLineData;
  TLineData=record
   Name:String[100];
   LastName:String[100];
   Bothday:String[10];
   Age:Integer;
   Telephone:String[15];
  end;

  TLineClipboard=class
  public
   LineData:TLineData;
   procedure CopyToClipboard;
   procedure PasteFromClipboard;
  end;

var
 CF_PERSONDATA:word;

implementation

{ TLineClipboard }
procedure TLineClipboard.CopyToClipboard;
var
 Data:THandle;
 DataPtr:Pointer;
begin
 //Выделяем память под данные
 Data:=GlobalAlloc(GMEM_MOVEABLE, SizeOf(LineData));
 try
  DataPtr:=GlobalLock(Data);
  Move(LineData, DataPtr^, SizeOf(TLineData));

  //Заполняем буфер обмена
  Clipboard.Open;
  Clipboard.SetAsHandle(CF_PERSONDATA, Data);
  Clipboard.AsText:=LineData.Name+#13#10+LineData.LastName+#13#10+
      LineData.Bothday+#13#10+IntToStr(LineData.Age)+#13#10+
      LineData.Telephone;
  Clipboard.Close;
  GlobalUnlock(Data);
 except
  GlobalFree(Data);
 end;
end;

procedure TLineClipboard.PasteFromClipboard;
var
 Data:THandle;
 DataPtr:Pointer;
begin
 Data:=ClipBoard.GetAsHandle(CF_PERSONDATA);
 if Data=0 then exit;

 DataPtr:=GlobalLock(Data);
 Move(DataPtr^, LineData, SizeOf(TLineData));

 GlobalUnlock(Data);
end;

initialization
 CF_PERSONDATA:=RegisterClipboardFormat('CF_PDATA');

end.
