ClipUnit.pas
上传用户:tj00001
上传日期:2007-01-07
资源大小:672k
文件大小:2k
源码类别:

行业应用

开发平台:

Delphi

  1. //---------------------------------------------------------------------------
  2. //(R)CopyRight KivenSoft International ,inc 1999
  3. //单元名称:剪贴单元
  4. //程序名称:电子书库
  5. //作    者:李会文
  6. //开始时间:1999.07.07
  7. //最后修改:1999.07.07
  8. //备注:此单元定义了树形视图中进行剪贴的方式
  9. //---------------------------------------------------------------------------
  10. unit ClipUnit;
  11. interface
  12. uses
  13.   Windows,CommCtrl, Classes, ComCtrls;
  14. type
  15.   TSrmClip=class
  16.   private
  17.     FNode:TTreeNode;
  18.     FMode:integer;
  19.   public
  20.     constructor Create;
  21.     procedure Cut(ANode:TTreeNode);   //剪切该标题
  22.     procedure Copy(ANode:TTreeNode);  //拷贝该标题
  23.     procedure Paste(ANode:TTreeNode); //粘贴该标题
  24.     property Node:TTreeNode read FNode;
  25.     property Mode:integer read FMode;
  26.   end;
  27. var
  28.   SrmClip:TSrmClip;
  29. implementation
  30. uses
  31.   MainUnit;
  32. constructor TSrmClip.Create;
  33. begin
  34.   FNode:=nil;
  35.   FMode:=-1;
  36. end;
  37. procedure TSrmClip.Cut(ANode:TTreeNode);   //剪切该标题
  38. begin
  39.   FNode:=ANode;
  40.   FMode:=0;
  41. end;
  42. procedure TSrmClip.Copy(ANode:TTreeNode);  //拷贝该标题
  43. begin
  44.   FNode:=ANode;
  45.   FMode:=1;
  46. end;
  47. procedure TSrmClip.Paste(ANode:TTreeNode); //粘贴该标题
  48. var
  49.   tmpNode:TTreeNode;
  50.   Ms:TMemoryStream;
  51.   Id:integer;
  52. begin
  53.   if (FMode=-1) or (FNode=nil) then exit;   //无剪切或拷贝时退出
  54.   if FMode=0 then        //剪切时
  55.   begin
  56.     FNode.MoveTo(ANode,naAddChildFirst);
  57.     SrmForm.TreeView.Selected:=FNode;
  58.   end
  59.   else if FMode=1 then
  60.   begin
  61.     tmpNode:=SrmForm.TreeView.Items.AddChildObjectFirst
  62.            (ANode,FNode.Text,pointer(-1));
  63.     tmpNode.ImageIndex:=FNode.ImageIndex;
  64.     SrmForm.TreeView.Selected:=tmpNode;
  65.     Srm.ReadItemHead(integer(FNode.Data));
  66.     Ms:=TMemoryStream.Create;
  67.     Srm.ReadItemData(Ms);
  68.     SrmForm.RichEdit.Lines.LoadFromStream(Ms);
  69.     Ms.Free;
  70.   end;
  71.   if SrmForm.TreeView.Selected.Parent=nil then Id:=0
  72.   else Id:=integer(SrmForm.TreeView.Selected.Parent.ItemId);
  73.   SendMessage(SrmForm.TreeView.Handle,TVM_SORTCHILDREN,0,Id);
  74.   FMode:=-1;
  75.   FNode:=nil;
  76. end;
  77. end.