不好意思,是这个问题,就是如果现在表的结构是
     1.1
         1.2
         1.2.1
         1.2.1.1
         1.2.2
         1.3
         1.4
         1.5
a.现在比如说要插入个数据:需要重新插入1.2的一条数据(点数还是不限制的),原先的1.2变成1.3,在现有情况下单元框选择到1.1点击插入就变成了:
     1.1   希望是这样:  1.1
         1.2                 1.2
     1.2                 1.3
         1.2.1               1.3.1
         1.2.1.1             1.3.1.1
         1.2.2               1.3.2
         1.3                 1.3
         1.4                 1.4  
         1.5                 1.5
                             1.6   
b.情况是一样的,现在需要在1.2.1下插入个子行(点数也是不限制的),变成这个样子了:
      1.1       希望是这样的:  1.1
      1.2                       1.2
      1.2.1                     1.2.1 
      1.2.1.1                   1.2.1.1
      1.2.1.1                   1.2.1.2
      1.2.2                     1.2.2
      1.3                       1.3 
      1.4                       1.4
      1.5                       1.5
   想分别用butoon3和button4解决插入序号和子序号的问题,这个能行吗?
       

解决方案 »

  1.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, AxCtrls, OleCtrls, VCF1, ComCtrls;type
      TForm1 = class(TForm)
        Button1: TButton;
        F1Book1: TF1Book;
        Button2: TButton;
        procedure Button1Click(Sender: TObject);
        procedure F1Book1SelChange(Sender: TObject);
        procedure FormCreate(Sender: TObject);
        procedure Button2Click(Sender: TObject);
        function IsSameFloor(str1,str2:string):boolean;//判断是否处于一层
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;
      index:integer=1;
      col:integer=1;
      FirstClick:Boolean=false;
    implementation{$R *.dfm}function GetCharCount(c:char;s:string):integer; 
    var i:integer;  //返回字符串某字符个数
    begin
    result:=0;
    for i:=1 to length(s) do
      if c=s[i] then
          result:=result+1;
    end;function RightPos(c:char;s:string):integer;
    var       //返回从右第一个字符出现的位置
    i:integer;
    begin
    result:=0;
    for i:=length(s) downto 1 do
       if c=s[i] then
          begin
          result:=i;
          break;
          end;
    end; function GetRightStr(s:string;c:char):string;  //返回某字符右边的字符串
    var i:integer;
    begin
    result:='';
    for i:=length(s) downto 1 do
       begin
       if s[i]=c then
          exit;
       result:=s[i]+result;
       end;
    end;function GetIncStr(s:string):string;//返回递增后的字符串
    var
    i:integer;
    s1,ss:string;
    begin
       ss:=GetRightStr(s,'.');
       delete(s,RightPos('.',s),length(ss)+1);
       i:=strtoint(ss);
       inc(i);
       result:=s+'.'+inttostr(i);
    end;function GetIndex(ii:integer):integer;
    var
    i,old:integer;
    str:string;
    begin
    i:=ii;
    str:=form1.F1Book1.TextRC[i,col];
    old:=GetCharCount('.',str);
    repeat
    inc(i);
    try
    str:=form1.F1Book1.TextRC[i,col];
    except
    break;
    end;
    until old=GetCharCount('.',str);
    result:=i;
    end;procedure TForm1.Button1Click(Sender: TObject);
    var
    oldstr,str:string;
    i:integer;
    begin
    if FirstClick then
       begin
       firstclick:=false;
       oldstr:=self.F1Book1.TextRC[index,col];
       i:=index;
       while true do
         begin
         try
         inc(i);
         str:=F1Book1.TextRC[i,col];
         if IsSameFloor(oldstr,str) then
            begin
            inc(index);
            end else break;
         except
         break;
         end;
         end;
       end;
    str:=self.F1Book1.TextRC[index,col];
    inc(index);
    F1Book1.InsertRange(index,1,index,1,2);
    self.F1Book1.TextRC[index,col]:=GetIncStr(str);
    end;procedure TForm1.F1Book1SelChange(Sender: TObject);
    begin
    if self.F1Book1.TextRC[self.F1Book1.SelStartRow,self.F1Book1.SelStartCol]<>'' then
       begin
       self.Button1.Enabled:=true;
       self.Button2.Enabled:=true;
       index:=self.F1Book1.SelStartRow;
       col:=self.F1Book1.SelStartCol;
       FirstClick:=true;
       end else begin
       self.Button1.Enabled:=false;
       self.Button2.Enabled:=false;
       end;
    end;procedure TForm1.FormCreate(Sender: TObject);
    begin
    self.F1Book1.TextRC[1,1]:='1.1';
    end;procedure TForm1.Button2Click(Sender: TObject);
    var
    oldstr,str:string;
    i:integer;
    begin
    if FirstClick then
       begin
       firstclick:=false;
       oldstr:=F1Book1.TextRC[index,col]+'.1';
          while true do
         begin
         try
         inc(i);
         str:=F1Book1.TextRC[i,col];
         if IsSameFloor(oldstr,str) then
            begin
            inc(index);
            end else break;
         except
         break;
         end;
         end;
       end;
    str:=self.F1Book1.TextRC[index,col];
    inc(index);
    F1Book1.InsertRange(index,1,index,1,2);
    self.F1Book1.TextRC[index,col]:=str+'.1';
    end;function GetLeftRightChar(c:char;s:string):string;
    var
    i:integer;
    begin //返回从最右边某个字符开始左边的数据
    i:=rightpos(c,s);
    result:=copy(s,1,i-1);
    end;function TForm1.IsSameFloor(str1, str2: string): boolean;
    var
    i:integer;
    begin
    if GetLeftRightChar('.',str1)=GetLeftRightChar('.',str2) then
       result:=true else result:=false;
    end;end.
      

  2.   

    上面那个还有问题,这个彻底弄好了
    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, AxCtrls, OleCtrls, VCF1, ComCtrls;type
      TForm1 = class(TForm)
        Button1: TButton;
        F1Book1: TF1Book;
        Button2: TButton;
        Button3: TButton;
        Button4: TButton;
        procedure F1Book1SelChange(Sender: TObject);
        procedure FormCreate(Sender: TObject);
        function IsSameFloor(str1,str2:string):boolean;//判断是否处于一层
        function GetLastRow:integer;//取得本列最后一行行号
        function IsFloorTail:integer;
        procedure Button1Click(Sender: TObject);
        procedure Button2Click(Sender: TObject);//判断当前行是否在本层的最后
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;
      index:integer=1;
      col:integer=1;
      FirstClick:Boolean=false;
      FloorTail:integer=1;//-1未知,0层中间,1层尾
    implementation{$R *.dfm}function GetCharCount(c:char;s:string):integer; 
    var i:integer;  //返回字符串某字符个数
    begin
    result:=0;
    for i:=1 to length(s) do
      if c=s[i] then
          result:=result+1;
    end;function RightPos(c:char;s:string):integer;
    var       //返回从右第一个字符出现的位置
    i:integer;
    begin
    result:=0;
    for i:=length(s) downto 1 do
       if c=s[i] then
          begin
          result:=i;
          break;
          end;
    end; function GetRightStr(s:string;c:char):string;  //返回某字符右边的字符串
    var i:integer;
    begin
    result:='';
    for i:=length(s) downto 1 do
       begin
       if s[i]=c then
          exit;
       result:=s[i]+result;
       end;
    end;function GetIncStr(s:string):string;//返回递增后的字符串
    var
    i:integer;
    s1,ss:string;
    begin
       ss:=GetRightStr(s,'.');
       delete(s,RightPos('.',s),length(ss)+1);
       i:=strtoint(ss);
       inc(i);
       result:=s+'.'+inttostr(i);
    end;function GetIndex(ii:integer):integer;
    var
    i,old:integer;
    str:string;
    begin
    i:=ii;
    str:=form1.F1Book1.TextRC[i,col];
    old:=GetCharCount('.',str);
    repeat
    inc(i);
    try
    str:=form1.F1Book1.TextRC[i,col];
    except
    break;
    end;
    until old=GetCharCount('.',str);
    result:=i;
    end;procedure TForm1.F1Book1SelChange(Sender: TObject);
    begin
    if self.F1Book1.TextRC[self.F1Book1.SelStartRow,self.F1Book1.SelStartCol]<>'' then
       begin
       self.Button1.Enabled:=true;
       self.Button2.Enabled:=true;
       index:=self.F1Book1.SelStartRow;
       col:=self.F1Book1.SelStartCol;
       FirstClick:=true;
       FloorTail:=-1;
       end else begin
       self.Button1.Enabled:=false;
       self.Button2.Enabled:=false;
       end;
    end;procedure TForm1.FormCreate(Sender: TObject);
    begin
    self.F1Book1.TextRC[1,1]:='1.1';
    end;function GetLeftRightChar(c:char;s:string):string;
    var
    i:integer;
    begin //返回从最右边某个字符开始左边的数据
    i:=rightpos(c,s);
    result:=copy(s,1,i-1);
    end;function TForm1.IsSameFloor(str1, str2: string): boolean;
    var
    i:integer;
    begin
    if GetLeftRightChar('.',str1)=GetLeftRightChar('.',str2) then
       result:=true else result:=false;
    end;function TForm1.GetLastRow: integer;
    var
    i:integer;
    begin
    result:=0;
    for i:=1 to 65536 do
      begin
      if F1Book1.TextRC[i,col]<>'' then
         inc(result) else break;
      end;
    end;function TForm1.IsFloorTail: integer;
    var
    tail,i:integer;
    oldstr,str:string;
    begin
    tail:=GetLastRow;
    if index>tail then begin result:=-1;exit;end;
    if index=tail then begin result:=1;exit;end;
    oldstr:=F1Book1.TextRC[index,col];
    result:=1;
    for i:=index+1 to tail do
       begin
       str:=F1Book1.TextRC[i,col];
       if IsSameFloor(oldstr,str) then
          begin
          result:=0;
          break;
          end;
       end;
    end;
    procedure TForm1.Button1Click(Sender: TObject);//插入一个,层不变,但值加1
    var
    TailRow,i:integer;//有数据的最后一行
    str,oldstr:string;
    begin
    if FirstClick then
       begin
       firstclick:=false;
       FloorTail:=IsFloorTail;//判断当前位置,是不是处于层尾,把结果存入FloorTail中
       end;
    str:=self.F1Book1.TextRC[index,col];//取得当前单元格里的字符串
    inc(index);
    F1Book1.InsertRange(index,1,index,1,2);//在当前单元格后面插入一个空白单元格
    self.F1Book1.TextRC[index,col]:=GetIncStr(str); //把字符串加1后放入增加的单元格
    //在这儿还要考虑后面是否还有同层的数据,没有同层数据的话就不用管它了,有的话都需要加1
    //判断有无同层数据的依据,主要是看它是否处于层中间
    //如果在层中间
    if FloorTail=0 then
       begin
       TailRow:=GetLastRow;//取得最后一行
       oldstr:=F1Book1.TextRC[index,col];//取得当前行的字符串,以备后面的同层判断
       for i:=index+1 to TailRow do//从当前行的下一行一直循环判断到最后一行
          begin
          str:=F1Book1.TextRC[i,col];
          if IsSameFloor(oldstr,str) then //只对同层数据处理
             begin
             F1Book1.TextRC[i,col]:=GetIncStr(str);//加1后放回原来位置
             end;
          end;
       end;
    end;procedure TForm1.Button2Click(Sender: TObject);//在当前行后面插入一项,增加一层
    var
    TailRow,i:integer;//有数据的最后一行
    str,oldstr:string;
    begin
    str:=self.F1Book1.TextRC[index,col];
    inc(index);
    F1Book1.InsertRange(index,1,index,1,2);
    self.F1Book1.TextRC[index,col]:=str+'.1';
    if FirstClick then
       begin
       FirstClick:=false;
       FloorTail:=IsFloorTail;//判断当前位置,是不是处于层尾,把结果存入FloorTail中
       end;
    if FloorTail=0 then //如果在层中间
       begin
       TailRow:=GetLastRow;//取得最后一行
       oldstr:=F1Book1.TextRC[index,col];//取得当前行的字符串,以备后面的同层判断
       for i:=index+1 to TailRow do//从当前行的下一行一直循环判断到最后一行
          begin
          str:=F1Book1.TextRC[i,col];
          if IsSameFloor(oldstr,str) then //只对同层数据处理
             begin
             F1Book1.TextRC[i,col]:=GetIncStr(str);//加1后放回原来位置
             end;
          end;
       end;
    end;end.
      

  3.   

    眼泪哇哇的,感动啊,谢谢!
    现在只有一个问题了:
    就是在添加的时候比如说表结构:
       1.1
       1.2
       1.3
       1.3.1
       1.3.2
       1.3.2.1
       1.3.2.1.1 
    现在我点击单选框1.3时,再点击button1(加同级别),变成这个样子:
     1.1              希望是这个样子: 1.1
     1.2                             1.2 
     1.3                             1.3
     1.4                             1.3.1
     1.3.1                           1.3.2 
     1.3.2                           1.3.2.1 
     1.3.2.1                         1.3.2.1.1
     1.3.2.1.1                       1.4
    不知道大侠遇到过这个问题没?
      

  4.   

    周末回家了,刚回来,
    点两下就可以了,可能是这个f1book是测试版的问题,点一下,当前行值不变
      

  5.   

    现在我点击单选框1.3时,
    这儿要点两下才能把当前行设为当前行值,可能是因为测试版的问题吧.我用click事件,也是同样的问题,需要点某个单元格两次,才能把当前行值设置过去,下面是我用click事件做的:
    procedure TForm1.F1Book1Click(Sender: TObject; nRow, nCol: Integer);
    begin
    if self.F1Book1.TextRC[{self.F1Book1.SelStartRow,self.F1Book1.SelStartCol}nrow,ncol]<>'' then
       begin
       self.Button1.Enabled:=true;
       self.Button2.Enabled:=true;
       index:=nrow;//self.F1Book1.SelStartRow;
       col:=ncol;//self.F1Book1.SelStartCol;
       FirstClick:=true;
       FloorTail:=-1;
       end else begin
       self.Button1.Enabled:=false;
       self.Button2.Enabled:=false;
       end;
    end;
      

  6.   

    刚才试了一下,是onselChange事件有问题,换成onclick可以了
    代码如下:
    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, AxCtrls, OleCtrls, VCF1, ComCtrls;type
      TForm1 = class(TForm)
        Button1: TButton;
        F1Book1: TF1Book;
        Button2: TButton;
        Button3: TButton;
        Button4: TButton;
        procedure FormCreate(Sender: TObject);
        function IsSameFloor(str1,str2:string):boolean;//判断是否处于一层
        function GetLastRow:integer;//取得本列最后一行行号
        function IsFloorTail:integer;
        procedure Button1Click(Sender: TObject);
        procedure Button2Click(Sender: TObject);
        procedure F1Book1Click(Sender: TObject; nRow, nCol: Integer);//判断当前行是否在本层的最后
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;
      index:integer=1;
      col:integer=1;
      FirstClick:Boolean=false;
      FloorTail:integer=1;//-1未知,0层中间,1层尾
    implementation{$R *.dfm}function GetCharCount(c:char;s:string):integer; 
    var i:integer;  //返回字符串某字符个数
    begin
    result:=0;
    for i:=1 to length(s) do
      if c=s[i] then
          result:=result+1;
    end;function RightPos(c:char;s:string):integer;
    var       //返回从右第一个字符出现的位置
    i:integer;
    begin
    result:=0;
    for i:=length(s) downto 1 do
       if c=s[i] then
          begin
          result:=i;
          break;
          end;
    end; function GetRightStr(s:string;c:char):string;  //返回某字符右边的字符串
    var i:integer;
    begin
    result:='';
    for i:=length(s) downto 1 do
       begin
       if s[i]=c then
          exit;
       result:=s[i]+result;
       end;
    end;function GetIncStr(s:string):string;//返回递增后的字符串
    var
    i:integer;
    s1,ss:string;
    begin
       ss:=GetRightStr(s,'.');
       delete(s,RightPos('.',s),length(ss)+1);
       i:=strtoint(ss);
       inc(i);
       result:=s+'.'+inttostr(i);
    end;function GetIndex(ii:integer):integer;
    var
    i,old:integer;
    str:string;
    begin
    i:=ii;
    str:=form1.F1Book1.TextRC[i,col];
    old:=GetCharCount('.',str);
    repeat
    inc(i);
    try
    str:=form1.F1Book1.TextRC[i,col];
    except
    break;
    end;
    until old=GetCharCount('.',str);
    result:=i;
    end;procedure TForm1.FormCreate(Sender: TObject);
    begin
    self.F1Book1.TextRC[1,1]:='1.1';
    end;function GetLeftRightChar(c:char;s:string):string;
    var
    i:integer;
    begin //返回从最右边某个字符开始左边的数据
    i:=rightpos(c,s);
    result:=copy(s,1,i-1);
    end;function TForm1.IsSameFloor(str1, str2: string): boolean;
    var
    i:integer;
    begin
    if GetLeftRightChar('.',str1)=GetLeftRightChar('.',str2) then
       result:=true else result:=false;
    end;function TForm1.GetLastRow: integer;
    var
    i:integer;
    begin
    result:=0;
    for i:=1 to 65536 do
      begin
      if F1Book1.TextRC[i,col]<>'' then
         inc(result) else break;
      end;
    end;function TForm1.IsFloorTail: integer;
    var
    tail,i:integer;
    oldstr,str:string;
    begin
    tail:=GetLastRow;
    if index>tail then begin result:=-1;exit;end;
    if index=tail then begin result:=1;exit;end;
    oldstr:=F1Book1.TextRC[index,col];
    result:=1;
    for i:=index+1 to tail do
       begin
       str:=F1Book1.TextRC[i,col];
       if IsSameFloor(oldstr,str) then
          begin
          result:=0;
          break;
          end;
       end;
    end;
    procedure TForm1.Button1Click(Sender: TObject);//插入一个,层不变,但值加1
    var
    TailRow,i:integer;//有数据的最后一行
    str,oldstr:string;
    begin
    if FirstClick then
       begin
       firstclick:=false;
       FloorTail:=IsFloorTail;//判断当前位置,是不是处于层尾,把结果存入FloorTail中
       end;
    str:=self.F1Book1.TextRC[index,col];//取得当前单元格里的字符串
    inc(index);
    F1Book1.InsertRange(index,1,index,1,2);//在当前单元格后面插入一个空白单元格
    self.F1Book1.TextRC[index,col]:=GetIncStr(str); //把字符串加1后放入增加的单元格
    //在这儿还要考虑后面是否还有同层的数据,没有同层数据的话就不用管它了,有的话都需要加1
    //判断有无同层数据的依据,主要是看它是否处于层中间
    //如果在层中间
    if FloorTail=0 then
       begin
       TailRow:=GetLastRow;//取得最后一行
       oldstr:=F1Book1.TextRC[index,col];//取得当前行的字符串,以备后面的同层判断
       for i:=index+1 to TailRow do//从当前行的下一行一直循环判断到最后一行
          begin
          str:=F1Book1.TextRC[i,col];
          if IsSameFloor(oldstr,str) then //只对同层数据处理
             begin
             F1Book1.TextRC[i,col]:=GetIncStr(str);//加1后放回原来位置
             end;
          end;
       end;
    end;procedure TForm1.Button2Click(Sender: TObject);//在当前行后面插入一项,增加一层
    var
    TailRow,i:integer;//有数据的最后一行
    str,oldstr:string;
    begin
    str:=self.F1Book1.TextRC[index,col];
    inc(index);
    F1Book1.InsertRange(index,1,index,1,2);
    self.F1Book1.TextRC[index,col]:=str+'.1';
    if FirstClick then
       begin
       FirstClick:=false;
       FloorTail:=IsFloorTail;//判断当前位置,是不是处于层尾,把结果存入FloorTail中
       end;
    if FloorTail=0 then //如果在层中间
       begin
       TailRow:=GetLastRow;//取得最后一行
       oldstr:=F1Book1.TextRC[index,col];//取得当前行的字符串,以备后面的同层判断
       for i:=index+1 to TailRow do//从当前行的下一行一直循环判断到最后一行
          begin
          str:=F1Book1.TextRC[i,col];
          if IsSameFloor(oldstr,str) then //只对同层数据处理
             begin
             F1Book1.TextRC[i,col]:=GetIncStr(str);//加1后放回原来位置
             end;
          end;
       end;
    end;procedure TForm1.F1Book1Click(Sender: TObject; nRow, nCol: Integer);
    begin
    if self.F1Book1.TextRC[{self.F1Book1.SelStartRow,self.F1Book1.SelStartCol}nrow,ncol]<>'' then
       begin
       self.Button1.Enabled:=true;
       self.Button2.Enabled:=true;
       index:=nrow;//self.F1Book1.SelStartRow;
       col:=ncol;//self.F1Book1.SelStartCol;
       FirstClick:=true;
       FloorTail:=-1;
       end else begin
       self.Button1.Enabled:=false;
       self.Button2.Enabled:=false;
       end;
    end;end.
      

  7.   

    我这儿也是点一下不起作用,点两下才起作用的,可能是f1book的版本的问题吧
      

  8.   

    to:“小和”:麻烦你这么试一下:
    点击button1,再点击button2,表的结构为:
    1.1
    1.2
    1.2.1
    现在选中1.2,再点击button1,就变成
    1.1
    1.2
    1.3
    1.2.1
    是不是这个样子?
      

  9.   

    这个倒没注意,中午回去我试试,你那儿是这样的吗,我这会儿在机房领着学生上机,手头没有delphi
      

  10.   

    点击button1,再点击button2,表的结构为: 
    1.1 
    1.2 
    1.2.1 
    现在选中1.2,再点击button1,就变成 
    1.1 
    1.2 
    1.3 
    1.2.1 
    是不是这个样子? 你是不是想要这个样子
    1.1 
    1.2 
    1.2.1
    1.3  
      

  11.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, AxCtrls, OleCtrls, VCF1, ComCtrls;type
      TForm1 = class(TForm)
        Button1: TButton;
        F1Book1: TF1Book;
        Button2: TButton;
        Button3: TButton;
        Button4: TButton;
        procedure FormCreate(Sender: TObject);
        function IsSameFloor(str1,str2:string):boolean;//判断是否处于一层
        function GetLastRow:integer;//取得本列最后一行行号
        function IsFloorTail:integer;
        procedure Button1Click(Sender: TObject);
        procedure Button2Click(Sender: TObject);
        procedure F1Book1Click(Sender: TObject; nRow, nCol: Integer);//判断当前行是否在本层的最后
        function FindInsertPoint:integer;//查找插入点
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;
      index:integer=1;
      col:integer=1;
      FirstClick:Boolean=false;
      FloorTail:integer=1;//-1未知,0层中间,1层尾
    implementation{$R *.dfm}function GetCharCount(c:char;s:string):integer; 
    var i:integer;  //返回字符串某字符个数
    begin
    result:=0;
    for i:=1 to length(s) do
      if c=s[i] then
          result:=result+1;
    end;function RightPos(c:char;s:string):integer;
    var       //返回从右第一个字符出现的位置
    i:integer;
    begin
    result:=0;
    for i:=length(s) downto 1 do
       if c=s[i] then
          begin
          result:=i;
          break;
          end;
    end; function GetRightStr(s:string;c:char):string;  //返回某字符右边的字符串
    var i:integer;
    begin
    result:='';
    for i:=length(s) downto 1 do
       begin
       if s[i]=c then
          exit;
       result:=s[i]+result;
       end;
    end;function GetIncStr(s:string):string;//返回递增后的字符串
    var
    i:integer;
    s1,ss:string;
    begin
       ss:=GetRightStr(s,'.');
       delete(s,RightPos('.',s),length(ss)+1);
       i:=strtoint(ss);
       inc(i);
       result:=s+'.'+inttostr(i);
    end;procedure TForm1.FormCreate(Sender: TObject);
    begin
    self.F1Book1.TextRC[1,1]:='1.1';
    end;function GetLeftRightChar(c:char;s:string):string;
    var
    i:integer;
    begin //返回从最右边某个字符开始左边的数据
    i:=rightpos(c,s);
    result:=copy(s,1,i-1);
    end;function TForm1.IsSameFloor(str1, str2: string): boolean;
    var
    i:integer;
    begin
    if (GetLeftRightChar('.',str1)=GetLeftRightChar('.',str2))or(str1=GetLeftRightChar('.',str2)) then
       result:=true else result:=false;
    end;function TForm1.GetLastRow: integer;
    var
    i:integer;
    begin
    result:=0;
    for i:=1 to 65536 do
      begin
      if F1Book1.TextRC[i,col]<>'' then
         inc(result) else break;
      end;
    end;function TForm1.IsFloorTail: integer;//是不是层尾
    var
    tail,i:integer;
    oldstr,str:string;
    begin
    tail:=GetLastRow;
    if index>tail then begin result:=-1;exit;end;
    if index=tail then begin result:=1;exit;end;
    oldstr:=F1Book1.TextRC[index,col];
    result:=1;
    for i:=index+1 to tail do
       begin
       str:=F1Book1.TextRC[i,col];
       if IsSameFloor(oldstr,str) then
          begin
          result:=0;
          break;
          end;
       end;
    end;
    procedure TForm1.Button1Click(Sender: TObject);//插入一个,层不变,但值加1
    var
    oldstr,str,tempstr:string;
    TailRow,i:integer;
    begin
    str:=self.F1Book1.TextRC[index,col];//取得当前单元格里的字符串
    if FirstClick then
       begin
       firstclick:=false;
       FloorTail:=IsFloorTail;//判断当前位置,是不是处于层尾,把结果存入FloorTail中
       index:=FindInsertPoint;
       end;
    tempstr:=self.F1Book1.TextRC[index,col];//取得当前单元格里的字符串
    if GetCharCount('.',str)=GetCharCount('.',tempstr) then
       str:=tempstr;
    inc(index);
    F1Book1.InsertRange(index,1,index,1,2);//在当前单元格后面插入一个空白单元格
    self.F1Book1.TextRC[index,col]:=GetIncStr(str); //把字符串加1后放入增加的单元格
    if FloorTail=0 then //如果在层中间
       begin
       TailRow:=GetLastRow;//取得最后一行
       oldstr:=F1Book1.TextRC[index,col];//取得当前行的字符串,以备后面的同层判断
       for i:=index+1 to TailRow do//从当前行的下一行一直循环判断到最后一行
          begin
          str:=F1Book1.TextRC[i,col];
          if IsSameFloor(oldstr,str) then //只对同层数据处理
             begin
             F1Book1.TextRC[i,col]:=GetIncStr(str);//加1后放回原来位置
             end;
          end;
       end;
    end;procedure TForm1.Button2Click(Sender: TObject);//在当前行后面插入一项,增加一层
    var
    TailRow,i:integer;//有数据的最后一行
    str,oldstr:string;
    begin
    str:=self.F1Book1.TextRC[index,col];
    inc(index);
    F1Book1.InsertRange(index,1,index,1,2);
    self.F1Book1.TextRC[index,col]:=str+'.1';
    if FirstClick then
       begin
       FirstClick:=false;
       FloorTail:=IsFloorTail;//判断当前位置,是不是处于层尾,把结果存入FloorTail中
       end;
    if FloorTail=0 then //如果在层中间
       begin
       TailRow:=GetLastRow;//取得最后一行
       oldstr:=F1Book1.TextRC[index,col];//取得当前行的字符串,以备后面的同层判断
       for i:=index+1 to TailRow do//从当前行的下一行一直循环判断到最后一行
          begin
          str:=F1Book1.TextRC[i,col];
          if IsSameFloor(oldstr,str) then //只对同层数据处理
             begin
             F1Book1.TextRC[i,col]:=GetIncStr(str);//加1后放回原来位置
             end;
          end;
       end;
    end;procedure TForm1.F1Book1Click(Sender: TObject; nRow, nCol: Integer);
    begin
    if self.F1Book1.TextRC[{self.F1Book1.SelStartRow,self.F1Book1.SelStartCol}nrow,ncol]<>'' then
       begin
       self.Button1.Enabled:=true;
       self.Button2.Enabled:=true;
       index:=nrow;//self.F1Book1.SelStartRow;
       col:=ncol;//self.F1Book1.SelStartCol;
       FirstClick:=true;
       FloorTail:=-1;
       end else begin
       self.Button1.Enabled:=false;
       self.Button2.Enabled:=false;
       end;
    end;function TForm1.FindInsertPoint: integer;
    var
    i,iTail:integer;
    oldstr,str:string;
    begin
    result:=index;
    oldstr:=F1Book1.TextRC[index,col];
    iTail:=GetLastRow;
    for i:=index+1 to iTail do
       begin
       str:=F1Book1.TextRC[i,col];
       if IsSameFloor(oldstr,str) then
          begin
          result:=i;
          end;
       end;
    end;end.
      

  12.   

    to"小和":我想这应该是检测出的最后一个问题吧?
     在表的末级如果有子序号的话就有问题,其他正常,
    a.比如说:
    1.1
    1.2
    1.3
    1.3.1
    这时候点击选择1.3,再点击button1.就变成
    1.1
    1.2
    1.3
    1.4
    1.3.1
    b.如果表结构是这样:
    1.1
    1.2
    1.2.1
    1.2.1.1
    1.3
    点击选择1.2.1,再点击button1.就变成
    1.1
    1.2
    1.2.1
    1.2.2
    1.2.1.1
    1.3
      

  13.   

    如果是这样:
    1.1
    1.2
    1.2.1
    1.3
    再选择1.2,再点击button1,就没问题!
      

  14.   

    重新修改,我先测试了一下,看来这次真的要浚工了
    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, AxCtrls, OleCtrls, VCF1, ComCtrls;type
      TForm1 = class(TForm)
        Button1: TButton;
        F1Book1: TF1Book;
        Button2: TButton;
        Button3: TButton;
        Button4: TButton;
        procedure FormCreate(Sender: TObject);
        function IsSameFloor(str1,str2:string):boolean;//判断是否处于一层
        function GetLastRow:integer;//取得本列最后一行行号
        function IsFloorTail:integer;
        procedure Button1Click(Sender: TObject);
        procedure Button2Click(Sender: TObject);
        procedure F1Book1Click(Sender: TObject; nRow, nCol: Integer);//判断当前行是否在本层的最后
        function FindInsertPoint(var IncStr:string):integer;//查找插入点
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;
      index:integer=1;
      col:integer=1;
      FirstClick:Boolean=false;
      FloorTail:integer=1;//-1未知,0层中间,1层尾
    implementation{$R *.dfm}function GetCharCount(c:char;s:string):integer; 
    var i:integer;  //返回字符串某字符个数
    begin
    result:=0;
    for i:=1 to length(s) do
      if c=s[i] then
          result:=result+1;
    end;function RightPos(c:char;s:string):integer;
    var       //返回从右第一个字符出现的位置
    i:integer;
    begin
    result:=0;
    for i:=length(s) downto 1 do
       if c=s[i] then
          begin
          result:=i;
          break;
          end;
    end; function GetRightStr(s:string;c:char):string;  //返回某字符右边的字符串
    var i:integer;
    begin
    result:='';
    for i:=length(s) downto 1 do
       begin
       if s[i]=c then
          exit;
       result:=s[i]+result;
       end;
    end;function GetIncStr(s:string):string;//返回递增后的字符串
    var
    i:integer;
    s1,ss:string;
    begin
       ss:=GetRightStr(s,'.');
       delete(s,RightPos('.',s),length(ss)+1);
       i:=strtoint(ss);
       inc(i);
       result:=s+'.'+inttostr(i);
    end;procedure TForm1.FormCreate(Sender: TObject);
    begin
    self.F1Book1.TextRC[1,1]:='1.1';
    end;function GetLeftRightChar(c:char;s:string):string;
    var
    i:integer;
    begin //返回从最右边某个字符开始左边的数据
    i:=rightpos(c,s);
    result:=copy(s,1,i-1);
    end;function TForm1.IsSameFloor(str1, str2: string): boolean;
    var
    i:integer;
    begin
    if (GetLeftRightChar('.',str1)=GetLeftRightChar('.',str2))or(str1=GetLeftRightChar('.',str2)) then
       result:=true else result:=false;
    end;function TForm1.GetLastRow: integer;
    var
    i:integer;
    begin
    result:=0;
    for i:=1 to 65536 do
      begin
      if F1Book1.TextRC[i,col]<>'' then
         inc(result) else break;
      end;
    end;function TForm1.IsFloorTail: integer;//是不是层尾
    var
    tail,i:integer;
    oldstr,str:string;
    begin
    tail:=GetLastRow;
    if index>tail then begin result:=-1;exit;end;
    if index=tail then begin result:=1;exit;end;
    oldstr:=F1Book1.TextRC[index,col];
    result:=1;
    for i:=index+1 to tail do
       begin
       str:=F1Book1.TextRC[i,col];
       if IsSameFloor(oldstr,str) then
          begin
          result:=0;
          break;
          end;
       end;
    end;
    procedure TForm1.Button1Click(Sender: TObject);//插入一个,层不变,但值加1
    var
    oldstr,str,tempstr:string;
    TailRow,i:integer;
    begin
    str:='';
    if FirstClick then
       begin
       firstclick:=false;
       FloorTail:=IsFloorTail;//判断当前位置,是不是处于层尾,把结果存入FloorTail中
       index:=FindInsertPoint(str);
       showmessage('第'+inttostr(index)+'行,字符串为:'+str);
       end;
    if str='' then
       str:=self.F1Book1.TextRC[index,col];
    inc(index);
    F1Book1.InsertRange(index,1,index,1,2);//在当前单元格后面插入一个空白单元格
    self.F1Book1.TextRC[index,col]:=GetIncStr(str); //把字符串加1后放入增加的单元格
    if FloorTail=0 then //如果在层中间
       begin
       TailRow:=GetLastRow;//取得最后一行
       oldstr:=F1Book1.TextRC[index,col];//取得当前行的字符串,以备后面的同层判断
       for i:=index+1 to TailRow do//从当前行的下一行一直循环判断到最后一行
          begin
          str:=F1Book1.TextRC[i,col];
          if IsSameFloor(oldstr,str) then //只对同层数据处理
             begin
             F1Book1.TextRC[i,col]:=GetIncStr(str);//加1后放回原来位置
             end;
          end;
       end;
    end;procedure TForm1.Button2Click(Sender: TObject);//在当前行后面插入一项,增加一层
    var
    TailRow,i:integer;//有数据的最后一行
    str,oldstr:string;
    begin
    str:=self.F1Book1.TextRC[index,col];
    inc(index);
    F1Book1.InsertRange(index,1,index,1,2);
    self.F1Book1.TextRC[index,col]:=str+'.1';
    if FirstClick then
       begin
       FirstClick:=false;
       FloorTail:=IsFloorTail;//判断当前位置,是不是处于层尾,把结果存入FloorTail中
       end;
    if FloorTail=0 then //如果在层中间
       begin
       TailRow:=GetLastRow;//取得最后一行
       oldstr:=F1Book1.TextRC[index,col];//取得当前行的字符串,以备后面的同层判断
       for i:=index+1 to TailRow do//从当前行的下一行一直循环判断到最后一行
          begin
          str:=F1Book1.TextRC[i,col];
          if IsSameFloor(oldstr,str) then //只对同层数据处理
             begin
             F1Book1.TextRC[i,col]:=GetIncStr(str);//加1后放回原来位置
             end;
          end;
       end;
    end;procedure TForm1.F1Book1Click(Sender: TObject; nRow, nCol: Integer);
    begin
    if self.F1Book1.TextRC[{self.F1Book1.SelStartRow,self.F1Book1.SelStartCol}nrow,ncol]<>'' then
       begin
       self.Button1.Enabled:=true;
       self.Button2.Enabled:=true;
       index:=nrow;//self.F1Book1.SelStartRow;
       col:=ncol;//self.F1Book1.SelStartCol;
       FirstClick:=true;
       FloorTail:=-1;
       end else begin
       self.Button1.Enabled:=false;
       self.Button2.Enabled:=false;
       end;
    end;function TForm1.FindInsertPoint(var IncStr:string): integer;
    var
    i,iTail:integer;
    oldstr,preStr,str:string;
    begin
    result:=index;
    oldstr:=F1Book1.TextRC[index,col];
    incStr:=oldstr;
    iTail:=GetLastRow;
    for i:=index+1 to iTail do
       begin
       str:=F1Book1.TextRC[i,col];
       PreStr:=F1Book1.TextRC[i-1,col];
       if (IsSameFloor(oldstr,str))or (IsSameFloor(PreStr,str)) then
          begin
          result:=i;
          if GetCharCount('.',IncStr)=GetCharCount('.',str) then
             incstr:=str;
          end;
       end;
    end;end.
      

  15.   

    Button1事件中有一句是这样的
     showmessage('第'+inttostr(index)+'行,字符串为:'+str); 
    这是我为了测试添加的,你把它注释掉就可以了
      

  16.   

    高手,那个问题解决了,这个问题又冒出来了:
    现在的表结构:
    1.1
    1.2
    1.2.1
    1.2.1.1
    1.2.2
    1.3
    现在选择1.2.1,点击button1,本来应该是1.2.2后加个1.2.3,可不是这样???
      

  17.   

    现在的表结构: 
    1.1 
    1.2 
    1.2.1 
    1.2.1.1 
    1.2.2 
    1.3 
    to“小和”:现在先选中1.2.1,点击button1,变成
    1.1 
    1.2 
    1.2.1 
    1.2.1.1 
    1.2.2
    1.2.3 
    1.3 
    再选中1.2,点击button1,变成
    1.1 
    1.2 
    1.2.1 
    1.2.1.1 
    1.2.2
    1.2.3 
    1.3 
    1.4
    再选中1.2.1,点击button1,变成
    1.1 
    1.2 
    1.2.1 
    1.2.1.1 
    1.2.2
    1.2.3 
    1.3 
    1.4
    1.2.4
    你那是不是这样?大侠
      

  18.   

    再试试这个
    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, AxCtrls, OleCtrls, VCF1, ComCtrls;type
      TForm1 = class(TForm)
        Button1: TButton;
        F1Book1: TF1Book;
        Button2: TButton;
        Button3: TButton;
        Button4: TButton;
        procedure FormCreate(Sender: TObject);
        function IsSameFloor(str1,str2:string):boolean;//判断是否处于一层
        function GetLastRow:integer;//取得本列最后一行行号
        function IsFloorTail:integer;
        procedure Button1Click(Sender: TObject);
        procedure Button2Click(Sender: TObject);
        procedure F1Book1Click(Sender: TObject; nRow, nCol: Integer);//判断当前行是否在本层的最后
        function FindInsertPoint:integer;//查找插入点
        function GetStr:string;
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;
      index:integer=1;
      col:integer=1;
      FirstClick:Boolean=false;
      FloorTail:integer=1;//-1未知,0层中间,1层尾
    implementation{$R *.dfm}function GetCharCount(c:char;s:string):integer; 
    var i:integer;  //返回字符串某字符个数
    begin
    result:=0;
    for i:=1 to length(s) do
      if c=s[i] then
          result:=result+1;
    end;function RightPos(c:char;s:string):integer;
    var       //返回从右第一个字符出现的位置
    i:integer;
    begin
    result:=0;
    for i:=length(s) downto 1 do
       if c=s[i] then
          begin
          result:=i;
          break;
          end;
    end; function GetRightStr(s:string;c:char):string;  //返回某字符右边的字符串
    var i:integer;
    begin
    result:='';
    for i:=length(s) downto 1 do
       begin
       if s[i]=c then
          exit;
       result:=s[i]+result;
       end;
    end;function GetIncStr(s:string):string;//返回递增后的字符串
    var
    i:integer;
    s1,ss:string;
    begin
       ss:=GetRightStr(s,'.');
       delete(s,RightPos('.',s),length(ss)+1);
       i:=strtoint(ss);
       inc(i);
       result:=s+'.'+inttostr(i);
    end;procedure TForm1.FormCreate(Sender: TObject);
    begin
    self.F1Book1.TextRC[1,1]:='1.1';
    end;function GetLeftRightChar(c:char;s:string):string;
    var
    i:integer;
    begin //返回从最右边某个字符开始左边的数据
    i:=rightpos(c,s);
    result:=copy(s,1,i-1);
    end;function TForm1.IsSameFloor(str1, str2: string): boolean;
    var
    i:integer;
    begin
    if (GetLeftRightChar('.',str1)=GetLeftRightChar('.',str2))or(str1=GetLeftRightChar('.',str2))
    or(GetLeftRightChar('.',str1)=str2) then
       result:=true else result:=false;
    end;function TForm1.GetLastRow: integer;
    var
    i:integer;
    begin
    result:=0;
    for i:=1 to 65536 do
      begin
      if F1Book1.TextRC[i,col]<>'' then
         inc(result) else break;
      end;
    end;function TForm1.IsFloorTail: integer;//是不是层尾
    var
    tail,i:integer;
    oldstr,str:string;
    begin
    tail:=GetLastRow;
    if index>tail then begin result:=-1;exit;end;
    if index=tail then begin result:=1;exit;end;
    oldstr:=F1Book1.TextRC[index,col];
    result:=1;
    for i:=index+1 to tail do
       begin
       str:=F1Book1.TextRC[i,col];
       if IsSameFloor(oldstr,str) then
          begin
          result:=0;
          break;
          end;
       end;
    end;
    procedure TForm1.Button1Click(Sender: TObject);//插入一个,层不变,但值加1
    var
    oldstr,str,tempstr:string;
    TailRow,i:integer;
    begin
    str:='';
    if FirstClick then
       begin
       firstclick:=false;
       FloorTail:=IsFloorTail;//判断当前位置,是不是处于层尾,把结果存入FloorTail中
       str:=GetStr;
       index:=FindInsertPoint;
       showmessage('第'+inttostr(index)+'行,字符串为:'+str);
       end;
    if str='' then
       str:=self.F1Book1.TextRC[index,col];
    inc(index);
    F1Book1.InsertRange(index,1,index,1,2);//在当前单元格后面插入一个空白单元格
    self.F1Book1.TextRC[index,col]:=GetIncStr(str); //把字符串加1后放入增加的单元格
    if FloorTail=0 then //如果在层中间
       begin
       TailRow:=GetLastRow;//取得最后一行
       oldstr:=F1Book1.TextRC[index,col];//取得当前行的字符串,以备后面的同层判断
       for i:=index+1 to TailRow do//从当前行的下一行一直循环判断到最后一行
          begin
          str:=F1Book1.TextRC[i,col];
          if IsSameFloor(oldstr,str) then //只对同层数据处理
             begin
             F1Book1.TextRC[i,col]:=GetIncStr(str);//加1后放回原来位置
             end;
          end;
       end;
    end;procedure TForm1.Button2Click(Sender: TObject);//在当前行后面插入一项,增加一层
    var
    TailRow,i:integer;//有数据的最后一行
    str,oldstr:string;
    begin
    str:=self.F1Book1.TextRC[index,col];
    inc(index);
    F1Book1.InsertRange(index,1,index,1,2);
    self.F1Book1.TextRC[index,col]:=str+'.1';
    if FirstClick then
       begin
       FirstClick:=false;
       FloorTail:=IsFloorTail;//判断当前位置,是不是处于层尾,把结果存入FloorTail中
       end;
    if FloorTail=0 then //如果在层中间
       begin
       TailRow:=GetLastRow;//取得最后一行
       oldstr:=F1Book1.TextRC[index,col];//取得当前行的字符串,以备后面的同层判断
       for i:=index+1 to TailRow do//从当前行的下一行一直循环判断到最后一行
          begin
          str:=F1Book1.TextRC[i,col];
          if IsSameFloor(oldstr,str) then //只对同层数据处理
             begin
             F1Book1.TextRC[i,col]:=GetIncStr(str);//加1后放回原来位置
             end;
          end;
       end;
    end;procedure TForm1.F1Book1Click(Sender: TObject; nRow, nCol: Integer);
    begin
    if self.F1Book1.TextRC[{self.F1Book1.SelStartRow,self.F1Book1.SelStartCol}nrow,ncol]<>'' then
       begin
       self.Button1.Enabled:=true;
       self.Button2.Enabled:=true;
       index:=nrow;//self.F1Book1.SelStartRow;
       col:=ncol;//self.F1Book1.SelStartCol;
       FirstClick:=true;
       FloorTail:=-1;
       end else begin
       self.Button1.Enabled:=false;
       self.Button2.Enabled:=false;
       end;
    end;function TForm1.FindInsertPoint: integer;
    var
    i,iTail:integer;
    oldstr,preStr,str:string;
    begin
    result:=index;
    oldstr:=F1Book1.TextRC[index,col];
    iTail:=GetLastRow;
    for i:=index+1 to iTail do
       begin
       str:=F1Book1.TextRC[i,col];
       PreStr:=F1Book1.TextRC[i-1,col];
       if (IsSameFloor(oldstr,str))or (IsSameFloor(PreStr,str)) then
          begin
          if (GetLeftRightChar('.',oldstr)=GetLeftRightChar('.',str))or
             (oldstr=GetLeftRightChar('.',str)) then
          result:=i;
          end;
       end;
    end;function TForm1.GetStr: string;
    var
    i,iTail:integer;
    oldstr,preStr,str,incStr:string;
    begin
    oldstr:=F1Book1.TextRC[index,col];
    incStr:=oldstr;
    iTail:=GetLastRow;
    for i:=index+1 to iTail do
       begin
       str:=F1Book1.TextRC[i,col];
       PreStr:=F1Book1.TextRC[i-1,col];
       if (IsSameFloor(oldstr,str))or (IsSameFloor(PreStr,str)) then
          begin
          if GetCharCount('.',IncStr)=GetCharCount('.',str) then
             begin
             incstr:=str;
             end;
          end;
       end;
    result:=IncStr;
    end;end.
      

  19.   

    上面代码经过测试,发现了点问题,重新修改如下,这次认真测试了下,到目前为止还没发现问题
    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, AxCtrls, OleCtrls, VCF1, ComCtrls;type
      TForm1 = class(TForm)
        Button1: TButton;
        F1Book1: TF1Book;
        Button2: TButton;
        Button3: TButton;
        Button4: TButton;
        procedure FormCreate(Sender: TObject);
        function IsSameFloor(str1,str2:string):boolean;//判断是否处于一层
        function GetLastRow:integer;//取得本列最后一行行号
        function IsFloorTail:integer;
        procedure Button1Click(Sender: TObject);
        procedure Button2Click(Sender: TObject);
        procedure F1Book1Click(Sender: TObject; nRow, nCol: Integer);//判断当前行是否在本层的最后
        function FindInsertPoint(var IncStr:string):integer;//查找插入点
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;
      index:integer=1;
      col:integer=1;
      FirstClick:Boolean=false;
      FloorTail:integer=1;//-1未知,0层中间,1层尾
    implementation{$R *.dfm}function GetCharCount(c:char;s:string):integer; 
    var i:integer;  //返回字符串某字符个数
    begin
    result:=0;
    for i:=1 to length(s) do
      if c=s[i] then
          result:=result+1;
    end;function RightPos(c:char;s:string):integer;
    var       //返回从右第一个字符出现的位置
    i:integer;
    begin
    result:=0;
    for i:=length(s) downto 1 do
       if c=s[i] then
          begin
          result:=i;
          break;
          end;
    end; function GetRightStr(s:string;c:char):string;  //返回某字符右边的字符串
    var i:integer;
    begin
    result:='';
    for i:=length(s) downto 1 do
       begin
       if s[i]=c then
          exit;
       result:=s[i]+result;
       end;
    end;function GetIncStr(s:string):string;//返回递增后的字符串
    var
    i:integer;
    s1,ss:string;
    begin
       ss:=GetRightStr(s,'.');
       delete(s,RightPos('.',s),length(ss)+1);
       i:=strtoint(ss);
       inc(i);
       result:=s+'.'+inttostr(i);
    end;procedure TForm1.FormCreate(Sender: TObject);
    begin
    self.F1Book1.TextRC[1,1]:='1.1';
    end;function GetLeftRightChar(c:char;s:string):string;
    var
    i:integer;
    begin //返回从最右边某个字符开始左边的数据
    i:=rightpos(c,s);
    result:=copy(s,1,i-1);
    end;function TForm1.IsSameFloor(str1, str2: string): boolean;
    var
    i:integer;
    begin
    if (GetLeftRightChar('.',str1)=GetLeftRightChar('.',str2))or(str1=GetLeftRightChar('.',str2))
    or(GetLeftRightChar('.',str1)=str2) then
       result:=true else result:=false;
    end;function TForm1.GetLastRow: integer;
    var
    i:integer;
    begin
    result:=0;
    for i:=1 to 65536 do
      begin
      if F1Book1.TextRC[i,col]<>'' then
         inc(result) else break;
      end;
    end;function TForm1.IsFloorTail: integer;//是不是层尾
    var
    tail,i:integer;
    oldstr,str:string;
    begin
    tail:=GetLastRow;
    if index>tail then begin result:=-1;exit;end;
    if index=tail then begin result:=1;exit;end;
    oldstr:=F1Book1.TextRC[index,col];
    result:=1;
    for i:=index+1 to tail do
       begin
       str:=F1Book1.TextRC[i,col];
       if IsSameFloor(oldstr,str) then
          begin
          result:=0;
          break;
          end;
       end;
    end;
    procedure TForm1.Button1Click(Sender: TObject);//插入一个,层不变,但值加1
    var
    oldstr,str,tempstr:string;
    TailRow,i:integer;
    begin
    str:='';
    if FirstClick then
       begin
       firstclick:=false;
       FloorTail:=IsFloorTail;//判断当前位置,是不是处于层尾,把结果存入FloorTail中
       //str:=GetStr;
       index:=FindInsertPoint(str);
    //   showmessage('第'+inttostr(index)+'行,字符串为:'+str);
       end;
    if str='' then
       str:=self.F1Book1.TextRC[index,col];
    inc(index);
    F1Book1.InsertRange(index,1,index,1,2);//在当前单元格后面插入一个空白单元格
    self.F1Book1.TextRC[index,col]:=GetIncStr(str); //把字符串加1后放入增加的单元格
    if FloorTail=0 then //如果在层中间
       begin
       TailRow:=GetLastRow;//取得最后一行
       oldstr:=F1Book1.TextRC[index,col];//取得当前行的字符串,以备后面的同层判断
       for i:=index+1 to TailRow do//从当前行的下一行一直循环判断到最后一行
          begin
          str:=F1Book1.TextRC[i,col];
          if IsSameFloor(oldstr,str) then //只对同层数据处理
             begin
             F1Book1.TextRC[i,col]:=GetIncStr(str);//加1后放回原来位置
             end;
          end;
       end;
    end;procedure TForm1.Button2Click(Sender: TObject);//在当前行后面插入一项,增加一层
    var
    TailRow,i:integer;//有数据的最后一行
    str,oldstr:string;
    begin
    str:=self.F1Book1.TextRC[index,col];
    inc(index);
    F1Book1.InsertRange(index,1,index,1,2);
    self.F1Book1.TextRC[index,col]:=str+'.1';
    if FirstClick then
       begin
       FirstClick:=false;
       FloorTail:=IsFloorTail;//判断当前位置,是不是处于层尾,把结果存入FloorTail中
       end;
    if FloorTail=0 then //如果在层中间
       begin
       TailRow:=GetLastRow;//取得最后一行
       oldstr:=F1Book1.TextRC[index,col];//取得当前行的字符串,以备后面的同层判断
       for i:=index+1 to TailRow do//从当前行的下一行一直循环判断到最后一行
          begin
          str:=F1Book1.TextRC[i,col];
          if IsSameFloor(oldstr,str) then //只对同层数据处理
             begin
             F1Book1.TextRC[i,col]:=GetIncStr(str);//加1后放回原来位置
             end;
          end;
       end;
    end;procedure TForm1.F1Book1Click(Sender: TObject; nRow, nCol: Integer);
    begin
    if self.F1Book1.TextRC[{self.F1Book1.SelStartRow,self.F1Book1.SelStartCol}nrow,ncol]<>'' then
       begin
       self.Button1.Enabled:=true;
       self.Button2.Enabled:=true;
       index:=nrow;//self.F1Book1.SelStartRow;
       col:=ncol;//self.F1Book1.SelStartCol;
       FirstClick:=true;
       FloorTail:=-1;
       end else begin
       self.Button1.Enabled:=false;
       self.Button2.Enabled:=false;
       end;
    end;function TForm1.FindInsertPoint(var IncStr:string): integer;
    var
    i,iTail:integer;
    oldstr,preStr,str:string;
    begin
    result:=index;
    oldstr:=F1Book1.TextRC[index,col];
    incStr:=oldstr;
    iTail:=GetLastRow;
    for i:=index+1 to iTail do
       begin
       str:=F1Book1.TextRC[i,col];
       PreStr:=F1Book1.TextRC[i-1,col];
       if (IsSameFloor(oldstr,str))or (IsSameFloor(PreStr,str)) then
          begin
          if (GetLeftRightChar('.',oldstr)=GetLeftRightChar('.',str))or
             (oldstr=GetLeftRightChar('.',str)) then
              begin
              if GetCharCount('.',IncStr)=GetCharCount('.',str) then
             begin
             incstr:=str;
             end;
              result:=i;
              end;
          end;
       end;
    end;end.
      

  20.   

    按钮1弄好了,按钮2还有问题,现修改如下,测试过没问题
    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, AxCtrls, OleCtrls, VCF1, ComCtrls;type
      TForm1 = class(TForm)
        Button1: TButton;
        F1Book1: TF1Book;
        Button2: TButton;
        Button3: TButton;
        Button4: TButton;
        procedure FormCreate(Sender: TObject);
        function IsSameFloor(str1,str2:string):boolean;//判断是否处于一层
        function GetLastRow:integer;//取得本列最后一行行号
        function IsFloorTail:integer;
        procedure Button1Click(Sender: TObject);
        procedure Button2Click(Sender: TObject);
        procedure F1Book1Click(Sender: TObject; nRow, nCol: Integer);//判断当前行是否在本层的最后
        function FindInsertPoint(var IncStr:string):integer;//查找插入点
        function FindInsertPoint2(var IncStr:string):integer;//查找插入点button2
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;
      index:integer=1;
      col:integer=1;
      FirstClick:Boolean=false;
      FloorTail:integer=1;//-1未知,0层中间,1层尾
    implementation{$R *.dfm}function GetCharCount(c:char;s:string):integer; 
    var i:integer;  //返回字符串某字符个数
    begin
    result:=0;
    for i:=1 to length(s) do
      if c=s[i] then
          result:=result+1;
    end;function RightPos(c:char;s:string):integer;
    var       //返回从右第一个字符出现的位置
    i:integer;
    begin
    result:=0;
    for i:=length(s) downto 1 do
       if c=s[i] then
          begin
          result:=i;
          break;
          end;
    end; function GetRightStr(s:string;c:char):string;  //返回某字符右边的字符串
    var i:integer;
    begin
    result:='';
    for i:=length(s) downto 1 do
       begin
       if s[i]=c then
          exit;
       result:=s[i]+result;
       end;
    end;function GetIncStr(s:string):string;//返回递增后的字符串
    var
    i:integer;
    s1,ss:string;
    begin
       ss:=GetRightStr(s,'.');
       delete(s,RightPos('.',s),length(ss)+1);
       i:=strtoint(ss);
       inc(i);
       result:=s+'.'+inttostr(i);
    end;procedure TForm1.FormCreate(Sender: TObject);
    begin
    self.F1Book1.TextRC[1,1]:='1.1';
    end;function GetLeftRightChar(c:char;s:string):string;
    var
    i:integer;
    begin //返回从最右边某个字符开始左边的数据
    i:=rightpos(c,s);
    result:=copy(s,1,i-1);
    end;function TForm1.IsSameFloor(str1, str2: string): boolean;
    var
    i:integer;
    begin
    if (GetLeftRightChar('.',str1)=GetLeftRightChar('.',str2))or(str1=GetLeftRightChar('.',str2))
    or(GetLeftRightChar('.',str1)=str2) then
       result:=true else result:=false;
    end;function TForm1.GetLastRow: integer;
    var
    i:integer;
    begin
    result:=0;
    for i:=1 to 65536 do
      begin
      if F1Book1.TextRC[i,col]<>'' then
         inc(result) else break;
      end;
    end;function TForm1.IsFloorTail: integer;//是不是层尾
    var
    tail,i:integer;
    oldstr,str:string;
    begin
    tail:=GetLastRow;
    if index>tail then begin result:=-1;exit;end;
    if index=tail then begin result:=1;exit;end;
    oldstr:=F1Book1.TextRC[index,col];
    result:=1;
    for i:=index+1 to tail do
       begin
       str:=F1Book1.TextRC[i,col];
       if IsSameFloor(oldstr,str) then
          begin
          result:=0;
          break;
          end;
       end;
    end;
    procedure TForm1.Button1Click(Sender: TObject);//插入一个,层不变,但值加1
    var
    oldstr,str,tempstr:string;
    TailRow,i:integer;
    begin
    str:='';
    if FirstClick then
       begin
       firstclick:=false;
       FloorTail:=IsFloorTail;//判断当前位置,是不是处于层尾,把结果存入FloorTail中
       index:=FindInsertPoint(str);
       end;
    if str='' then
       str:=self.F1Book1.TextRC[index,col];
    inc(index);
    F1Book1.InsertRange(index,1,index,1,2);//在当前单元格后面插入一个空白单元格
    self.F1Book1.TextRC[index,col]:=GetIncStr(str); //把字符串加1后放入增加的单元格
    if FloorTail=0 then //如果在层中间
       begin
       TailRow:=GetLastRow;//取得最后一行
       oldstr:=F1Book1.TextRC[index,col];//取得当前行的字符串,以备后面的同层判断
       for i:=index+1 to TailRow do//从当前行的下一行一直循环判断到最后一行
          begin
          str:=F1Book1.TextRC[i,col];
          if IsSameFloor(oldstr,str) then //只对同层数据处理
             begin
             F1Book1.TextRC[i,col]:=GetIncStr(str);//加1后放回原来位置
             end;
          end;
       end;
    end;procedure TForm1.Button2Click(Sender: TObject);//在当前行后面插入一项,增加一层
    var
    oldstr,str:string;
    i,tailrow:integer;
    begin
    index:=FindInsertPoint2(str);
    inc(index);
    F1Book1.InsertRange(index,1,index,1,2);
    self.F1Book1.TextRC[index,col]:=str;
    //showmessage('第'+inttostr(index)+'行,字符串为:'+str);
    if FirstClick then
       begin
       FirstClick:=false;
       FloorTail:=IsFloorTail;//判断当前位置,是不是处于层尾,把结果存入FloorTail中
       end;
    if FloorTail=0 then //如果在层中间
       begin
       TailRow:=GetLastRow;//取得最后一行
       oldstr:=str;
       for i:=index+1 to TailRow do//从当前行的下一行一直循环判断到最后一行
          begin
          str:=F1Book1.TextRC[i,col];
          if IsSameFloor(oldstr,str) then //只对同层数据处理
             begin
             F1Book1.TextRC[i,col]:=GetIncStr(str);//加1后放回原来位置
             end;
          end;
       end;
    end;procedure TForm1.F1Book1Click(Sender: TObject; nRow, nCol: Integer);
    begin
    if self.F1Book1.TextRC[{self.F1Book1.SelStartRow,self.F1Book1.SelStartCol}nrow,ncol]<>'' then
       begin
       self.Button1.Enabled:=true;
       self.Button2.Enabled:=true;
       index:=nrow;//self.F1Book1.SelStartRow;
       col:=ncol;//self.F1Book1.SelStartCol;
       FirstClick:=true;
       FloorTail:=-1;
       end else begin
       self.Button1.Enabled:=false;
       self.Button2.Enabled:=false;
       end;
    end;function TForm1.FindInsertPoint(var IncStr:string): integer;
    var
    i,iTail:integer;
    oldstr,preStr,str:string;
    begin
    result:=index;
    oldstr:=F1Book1.TextRC[index,col];
    incStr:=oldstr;
    iTail:=GetLastRow;
    for i:=index+1 to iTail do
       begin
       str:=F1Book1.TextRC[i,col];
       PreStr:=F1Book1.TextRC[i-1,col];
       if (IsSameFloor(oldstr,str))or (IsSameFloor(PreStr,str)) then
          begin
          if (GetLeftRightChar('.',oldstr)=GetLeftRightChar('.',str))or
             (oldstr=GetLeftRightChar('.',str)) then
              begin
              if GetCharCount('.',IncStr)=GetCharCount('.',str) then
                 begin
                 incstr:=str;
                 end;
              result:=i;
              end;
          end;
       end;
    end;function TForm1.FindInsertPoint2(var IncStr: string): integer;
    var
    i,iTail:integer;
    oldstr,preStr,str:string;
    begin
    result:=index;
    oldstr:=F1Book1.TextRC[index,col]+'.1';
    incStr:=oldstr;
    iTail:=GetLastRow;
    //showmessage(inttostr(index+1));
    for i:=index+1 to iTail do
       begin
       str:=F1Book1.TextRC[i,col];
       PreStr:=F1Book1.TextRC[i-1,col];
       if (IsSameFloor(oldstr,str))or (IsSameFloor(PreStr,str)) then
          begin
          if (GetLeftRightChar('.',oldstr)=GetLeftRightChar('.',str))or
             (oldstr=GetLeftRightChar('.',str)) then
              begin
              if GetCharCount('.',IncStr)=GetCharCount('.',str) then
                 begin
                 incstr:=getincstr(str);
                 end;
              result:=i;
              end;
          end;
       end;
    end;end.
      

  21.   

    to"小和":
    现在的表结构为
    1.1
    1.2
    1.3
    1.4
    1.5
    1.5.1
    1.5.1.1
    1.5.1.1.1
    1.5.1.1.1.1
    现在选中1.2,点击button1,就变成了
    1.1
    1.2
    1.3
    1.4
    1.5
    1.6
    1.5.1
    1.5.1.1
    1.5.1.1.1
    1.5.1.1.1.1
    还有就是插入中间的时候,也是这种情况:
    1.1
    1.2
    1.2.1
    1.2.1.1
    1.2.1.1.1
    1.2.1.1.1.1
    1.3
    1.4
    1.5
    选中1.2,点击button2,变成:
    1.1
    1.2
    1.2.1
    1.2.2
    1.2.1.1
    1.2.1.1.1
    1.2.1.1.1.1
    1.3
    1.4
    1.5