解决了datatree的‘死节点’问题

页面导航:首页 > 软件编程 > Delphi > 解决了datatree的‘死节点’问题

解决了datatree的‘死节点’问题

来源: 作者: 时间:2016-02-05 11:47 【

//问题描述见 howto 一文,代码最终版本见下文//标红色部分为解决问题的关键//标蓝色部分为datatree所要求的,即前文提供的解决方案,但并不奏效procedure TScriptProperty.DataTreeDragDrop(Sende

//问题描述见 howto 一文,代码最终版本见下文

//标红色部分为解决问题的关键

//标蓝色部分为datatree所要求的,即前文提供的解决方案,但并不奏效

procedure TScriptProperty.DataTreeDragDrop(Sender: TBaseVirtualTree;
  Source: TObject; DataObject: IDataObject; Formats: TFormatArray;
  Shift: TShiftState; Pt: TPoint; var Effect: Integer; Mode: TDropMode);
var
  pnode2: PAdminNode;
  data: PInt;
  Node2: PVirtualNode;
  sql: string;

  changeList: TStringList;
  FocusNode: PVirtualNode;
  TargetNode: PVirtualNode;
  Temp:PVirtualNode;
  i: Integer;
  left,right,targe:Integer;
begin
  Effect := DROPEFFECT_NONE;
  if (Source is TBaseVirtualTree) then
  begin
    Node2 := (Source as TBaseVirtualTree).GetFirstSelected;
    data := (Source as TBaseVirtualTree).GetNodeData(Node2);
    pnode2 := Pointer(data^);

    FocusNode := Sender.GetFirstSelected;
    TargetNode := Sender.DropTargetNode;

    left :=LeftBracketIndex(FocusNode);
    right:=RightBracketIndex(FocusNode);
    if TargetNode <> nil then
      targe := TargetNode.Index
    else
      targe := -1;
    if (Source as TBaseVirtualTree).Name = DataTree then
    begin
      if DataTree.DropTargetNode = nil then Exit;
      if DataTree.DropTargetNode.Index = 0 then Exit;
      changeList := TStringList.Create;

      DataTree.BeginUpdate;

//块拖动问题

      if (left<>0) and (right<>0)and (left<>LeftBracketIndex(TargetNode))and (right <>RightBracketIndex (TargetNode)) then  //后两个条件解决了同一块类不能移动的问题
      begin
        if  right< targe then
        begin
           if (LeftStr(stringlist.Strings[targe],5)=While) or (LeftStr(stringlist.Strings[targe],3)=for) then
              Exit;
           for i:=right+ 1 to targe do
               changeList.Add(stringlist.Strings[i]);
           for i:=left-1 to right do
               changeList.Add(stringlist.Strings[i]);
           for i:=left-1 to targe do
               stringlist.Strings[i]:= changeList.Strings[i-left+1];
        end;

        if  (left-1)> targe then
        begin
          if (stringlist.Strings[targe]={)  then
              exit;
          for i:=left-1 to right do
              changeList.Add(stringlist.Strings[i]);
          for i:=targe to left-2 do
              changeList.Add(stringlist.Strings[i]);
          for i:=targe to right do
              stringlist.Strings[i]:= changeList.Strings[i-targe];
        end;
      end
      else
      begin
        if FocusNode.Index > TargetNode.Index then
        begin
          if (stringlist.Strings[TargetNode.Index]={)  then
              exit;
          changeList.Add(stringlist.Strings[FocusNode.index]);
          for i:=TargetNode.Index to FocusNode.Index-1 do

Tags:

相关文章

    文章评论

    最 近 更 新
    热 点 排 行
    Js与CSS工具
    代码转换工具
    
    <